I have a custome memory manager that overrides the new and delete operator in a pretty basic way:
#define MARY_DEBUG_NEW new(__FILE__, __LINE__)
#define MARY_DEBUG_NEW new
#define new MARY_DEBUG_NEW
Now this works fine for almost evrything and anything except in one small area. I have started to work with AngelScript, and to use custom classes with the script (including strings) i need to use new in a way I have never seen before.
static void ConstructString(CScriptString* _thisPointer)
Now I need to alter my memory manager so that it can handle this syntax, but I have no idea how to do this, as I have _no_ idea what it does. According to the author of AngelScript, the _thisPointer has already been allocated, so i am assuming it just calls the constructor, and sets up the object.
Is this correct? IF it is, does anyone know how to implment this in my memory manager?
Thanks in advance
this is called "placement new" which is used to construct an object on a pre-allocated buffer. Example:
char *buffer = new char; // pre-allocated buffer
string *ptr = new (buffer) string("hello world!"); // contruct string in buffer
To overload it, you need to redefine the following interface:
void operator new(size_t, void *where)
Hope that helps.
Thanks a lot for that. I have found a way around using the new operator (which i prefer), meaning after 2 days of trying none stop it finally works!
Thanks for the info though, surprising what you dont know sometimes