I have a question related to placement new.
When dealing with objects, in order to destroy an object created with placement new it has to be called the destructor of the object explicity; that is:
#include <new>
using namespace std;
//The following command really allocates the splace
char * rawStorage = new char[ 2000 ];
//Placement new: It creates MyObject using the previous allocated space
MyObject* pmyObject = new (rawStorage) MyObject();
//To destroy MyObject
pmyObject->~MyObject();
//To destroy the raw storage
delete[] rawStorage
However, in some cases a part from building and object I have to use the raw storage in order to store an unsigned char array; that is:
#include <new>
using namespace std;
char * rawStorage = new char[ 2000 ];
//Placement new
unsigned char* arrayUnsignedChar = new (rawStorage) unsigned char[ 1000 ];
//The question is: how can be destroyed the "arrayUnsignedChar"
arrayUnsignedChar->?????????????
//To destroy the raw storage
delete[] rawStorage
So, how can I "destroy", not the raw storage, but the "arrayUnsignedChar"?
Perhaps in the case of an array of UnsignedChar there is no need to call any kind of destructor or function -perhaps it could be done a "reset" of the contents doing something like: memset(arrayUnsignedChar, 0x00, size);-