I have some code:
MemoryManager mm;
char *a = new (mm) char [len +1];
How can I free all the memory by pointer a?
I have some code:
MemoryManager mm;
char *a = new (mm) char [len +1];
How can I free all the memory by pointer a?
Firstly, there's no way that anything builtin can know how to delete your a
data - you're the one that allocated it with placement new, so it's your job to clean it up.
Unfortunatly, there doesn't appear to be a way of overloading delete
for this. Just use a method name of your choice:
MemoryManager mm;
char *a = new (mm) char [len +1];
mm.cleanup(a); // since mm allocated us the memory, only it knows how to destroy it.
// Note that this also needs to do obj.~ClassName() for class types
See 'is there a placement delete' in the isocpp faq.