Why c++ not support placement delete

X

XHengDF

something like this:
T *p = new(Alloc&)T;
delete(Alloc&) p;
is that will take problems!
now we could use Dealloc(Alloc&, void *p);
in the bs's tech Faq, i could not find the reason why not take the
placement delete to the language!

thinks;
 
B

benben

something like this:
T *p = new(Alloc&)T;

Alloc& cannot be a pointer. Perhaps you mean &Alloc?
delete(Alloc&) p;
is that will take problems!
now we could use Dealloc(Alloc&, void *p);
in the bs's tech Faq, i could not find the reason why not take the
placement delete to the language!

thinks;

a placement new doesn't really allocate memory. It simply calls the
constructor.

To destroy an object without deallocating the memory, simply call the
destructor:

void* rawptr = malloc(sizeof(T));
T* p = new(rawptr) T;
p->~T(); // destruction, but not deallocation
free(rawptr); // deallocation

Regards,
Ben
 
T

Tomás

posted:
something like this:
T *p = new(Alloc&)T;
delete(Alloc&) p;
is that will take problems!
now we could use Dealloc(Alloc&, void *p);
in the bs's tech Faq, i could not find the reason why not take the
placement delete to the language!

thinks;

I've often thought that "placement new" is a bad name for it, because
it's got nothing to do with the allocation of memory.

All it does is call the constructor.


-Tomás
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top