mardi 26 janvier 2016

std::shared_ptr with custom deleter does not copy the deleter when copy constructing

I have the following shared pointer which needs to be AVX aligned (256bits):

std::shared_ptr<int> data;
data.reset(alignedAlloc(size), alignedDeleter);

The alignedDeleter function contains a debug message, it prints correctly when data is destroyed.

Then I create a second shared pointer like this:

std::shared_ptr<int> * shared = new std::shared_ptr<int>(data);

Then data is destroyed, and delete shared; is called. The alignedDeleter function is never called this time.

It seems the copy constructor is not taking the deleter from the original object, is this possible, and why?

Aucun commentaire:

Enregistrer un commentaire