We have a library that provides a C interface via extern "C"
, and is used from C code, but inside it uses STL containers and some C++ features like RAII for convenience.
Now there is a new requirement that the library should be able to take pointers to a custom malloc
and free
function coming from the client code, and use that for allocations inside. I can place them into the context structure of the library, and use them where needed, but using them with STL is puzzling...
I looked at allocator classes but it seems STL containers must be able to use the default constructors to create the allocator and it seems there is no way to place these pointers into them to let them call through them to do the allocations.
Is it possible to work this around preferably in a thread safe manner (without using globals)?