I'm creating a custom memory allocator on top of the cstdlib malloc() and free() functions (for performance reasons). The allocator is within a simple class that stores a few memory buffers and miscellaneous parameters. I would like to name the method for freeing memory free(), however I need to still be able to use cstdlib's free() from within the class.
#include <cstdlib>
inline void cstdlib_free(void * M){ free(M); } // Works, but is ugly!
class MyAllocator{
/* ... */
// Does internal class operations; Does NOT use stdlib's free
free(void * _Memory){ /* ... */ }
// Frees buffers to system memory; USES stdlib's free
clear(void){
/* ... */
cstdlib_free(Buff); // THIS is what I want to change
/* ... */
}
};
For the moment, I solved this by creating a wrapper for cstdlib's free(), but I can't help but think there must be a better solution (I also don't want to rename the class's free() method, as I wanted the names to be consistent). I was hoping for a solution along the lines of the first answer of this question, that is, using the base class of cstdlib to access free().
Does C++ provide any method to access the standard C functions as a class structure? Is there some way I can tell the compiler I want to use the scope directly under the class declaration (without it being its superclass, which in this case does not even exist!)?