First, not to the OP but to other readers: as I understand it the OP is not talking about constructing an object in preallocated storage.
And I'm not talking about that.
To OP: you don't, just let your placement form of operator delete
forward to the ordinary operator delete
. After all that's the deallocation function that will be called for any successfully constructed dynamically allocated object. So you need to support it no matter what.
If you want to associate debug information with the allocated memory for use in the deallocation function then one practical option is to allocate a bit more than requested and place the info at the start or end of that block, return pointer to the unused portion. Then operator delete
needs to do the opposite. Caution: alignment.
I guess an impractical option is to use a static std::map
(or other associative array, like a hash table). It runs in thread safety issues and such, but it avoids alignment issue.
Cheers & hth.,