T
Tomás Ó hÉilidhe
"delete" does two things:
1) Invokes the destructor
2) Deallocates the memory
We can manually invoke the destructor with:
p->~T();
But is there any way to manually deallocate the memory without invoking
the destructor? Something like "placement delete" perhaps? I'd be using
it where I'd be continuously constructing and destroying an object:
T *const p = new T;
p->~T();
::new(p) T;
p->~T();
::new(p) T;
p->~T();
::new(p) T;
p->~T();
::new(p) T;
p->~T();
SomeSortOfPlacementDelete(p); /* Just de-allocate, don't destruct */
1) Invokes the destructor
2) Deallocates the memory
We can manually invoke the destructor with:
p->~T();
But is there any way to manually deallocate the memory without invoking
the destructor? Something like "placement delete" perhaps? I'd be using
it where I'd be continuously constructing and destroying an object:
T *const p = new T;
p->~T();
::new(p) T;
p->~T();
::new(p) T;
p->~T();
::new(p) T;
p->~T();
::new(p) T;
p->~T();
SomeSortOfPlacementDelete(p); /* Just de-allocate, don't destruct */