Proposal for dual memory management

Petr Janda janda.petr at gmail.com
Tue Jul 27 23:54:56 PDT 2010


Looking at TDPL, placement new can actually take a memory address.

So Im thinking why not do this:

void* mp = alloc!Foo(); // allocate raw memory off the C heap to hold Foo.
Foo* f = new(mp) Foo(); // construct an object in the memory pointed to by mp

and then

clear(f); // call destructor on f, obliterate with Buffer.init and then call
Buffer's default constructor as per TDPL
dealloc(mp); //deallocate memory

We reached the desired removal of delete without breaking TDPL.

Any comments about how possible or not possible it is to do?


More information about the Digitalmars-d mailing list