L
LuB
I am constantly creating and destroying a singular object used within
a class I wrote.
To save a bit of time, I am considering using 'placement new'. I guess
we could also debate this decision - but for the sake of this post ...
I'm searching for an answer that assumes said decision.
If I allocate memory in the class declaration:
char buffer[sizeof(ObjectX)];
and use 'placement new' inside of of an instance' method:
pObjectX = new (buffer) ObjectX;
then, when it comes time to clean up, I understand that I must
explicitly invoke the destructor .... but its not clear to me if I
need to use placement delete at all?
pObjectX->~ObjectX();
operator delete (pObjectX_, buffer); // ?????? is this or some
version of this required? or more-safe?
Especially considering, I am just going to create the object again and
again ... and I'm not relinquishing control of the memory space back
to the OS. ctor, dtor, ctor, dtor ... just not sure what delete does
in this case.
I guess I'm just not sure what operator delete (arg1, arg2) does? and
if its required when using placement new.
Thanks in advance,
-Luther
a class I wrote.
To save a bit of time, I am considering using 'placement new'. I guess
we could also debate this decision - but for the sake of this post ...
I'm searching for an answer that assumes said decision.
If I allocate memory in the class declaration:
char buffer[sizeof(ObjectX)];
and use 'placement new' inside of of an instance' method:
pObjectX = new (buffer) ObjectX;
then, when it comes time to clean up, I understand that I must
explicitly invoke the destructor .... but its not clear to me if I
need to use placement delete at all?
pObjectX->~ObjectX();
operator delete (pObjectX_, buffer); // ?????? is this or some
version of this required? or more-safe?
Especially considering, I am just going to create the object again and
again ... and I'm not relinquishing control of the memory space back
to the OS. ctor, dtor, ctor, dtor ... just not sure what delete does
in this case.
I guess I'm just not sure what operator delete (arg1, arg2) does? and
if its required when using placement new.
Thanks in advance,
-Luther