I am looking for a solution, which would allow me to use a singleton with overloaded new/delete. Basically, I need to overload global new/delete operators and I already have my own memory manager, which does not rely on new/delete at all. The problem is, it is an object-oriented code and I need to instantiate this manager somehow. I have been using DLL so far, but since I do not consider this a good solution, I would like to replace this with a static library instead.
The problem appears when dynamic initialization of global variables begin. Since the order of global initialization may vary, how would I construct my manager? Worse, how would I destroy it?
/* Manager definition */
void* operator new(std::size_t Size)
void operator delete(void* Ptr)
It can't be a simple global variable. I was considering static variable (or something like this) inside new(), but then I have no control on destroying it.
The solution can be platform-specific (for GCC) I was looking for some non-standard routine, which would be called before any global initialization and after global finalization (could use placement new then). Is there something like this? Or should I get back to DLLs?