I am implementing allocators in my program. I use C++ (But not so much 'modern' c++).
I have implemented a number of memory allocators which return memory mostly based on the required lifetime of the data so I don't in general need to do anything to 'free' allocations, I instead discard the whole memory block at certain times in the program.
In general this works well. My program is quite a bit faster than just using new/delete or malloc/free.
However imagine I have a function "get_computer_name" which gets the name of the computer using win32 api and returns it as a string. (Pretend it's different every time so I can't just store it once). It needs to allocate some memory to store the name. A lot of the time the lifetime of this data is just the calling function (as it just logs the name, or appends it to a larger string) so I can use a StackAllocator but sometimes I want full heap allocation.
So I pass in an allocator telling it where to allocate the string. All is good, it works well.
However, this is leading to an explosion of allocator parameters. Pretty much every function in my code is ending up taking an allocator as a parameter because either _it_ does allocation, or it calls a function that does so it needs to forward the allocator.
I don't really want most of the functions in my program to take an allocator as a parameter, it seems like clutter in the code...
Has anyone got any good ideas how to avoid passing allocators _everywhere_ in my code in an elegant way?