I am looking for a way to put large arrays of data (stored inside a class holding basic functionality like checks on the data, size etc) into any STL container, like a vector or a queue (FIFO queue is best since I have a producer and a consumer).
The problem is that I have to implement the copy constructor and.. well.. I don’t want to make a deep copy (since it takes too much time, so I stick to a shallow copy), but then again I have the problem of not knowing when to delete the array of data in the destructor (since I call the destructor twice and only have the data once, plus, the first call to the destructor likely comes from inserting/moving the element in the container, so I still need the array-data at that point).
I thought about using smart pointers like std::shared_ptr for the data array, but from what I have read they don’t call delete [] but rather delete – which is a shame since I have an ordinary array [].
Right now I have a solution that by hand calls a “DeleteArray” function on the class before removing it from the container. It works great but.. it is not nice.
Any ideas?
Boost has a
shared_arrayclass that is likeshared_ptrbut will usedelete[], or you can add a custom deleter toshared_ptrthat will make it calldelete[].