Topic: Placement delete suggestion
Author: boukanov@hadron.fi.uib.no (Igor Boukanov)
Date: 1996/03/30 Raw View
Dietmar Kuehl (kuehl@uzwil.informatik.uni-konstanz.de) wrote:
> OTOH, as Tim Hollebeek observed in a thread in comp.lang.c++.moderated
> (Placement new and arrays), the usefulness of placement array new is
> limited anyway: There is no portable way to figure out how much
> "allocation overhead" there will be and thus it is impossible to
> predict how much memory has to be set aside for a placement array new.
But there is a way to way to figure out how much is "allocation overhead"!
Here an example:
void* operator new[](size_t size, size_t& retSize) {
retSize = size;
return NULL;
}
So you can call write something like this:
class T { ... };
...
size_t size;
new(size) T[100];
T* p = new(alloca(size)) T[100]; // allocate memory from stack
...
for (int i = 99; i >= 0; i--) { p[i].~T(); }
// instead of placement delete ...
--
With best regards, Igor Boukanov
igor.boukanov@fi.uib.no http://www.fi.uib.no/~boukanov
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]