Declaration
template<class T>
class MarshallableDelete;
template<class T>
class MarshallableDelete<T[]>;Description
The MarshallableDelete helper provides a custom deleter suitable for use with std::unique_ptr when a pointer needs to cross an assembly boundary but must still be deleted from the assembly that originally created it. The deleter stores a small shared reference-counted helper object, which keeps the actual delete operation anchored to the originating module. The MarshallableDelete<T[]> specialization performs the corresponding array deletion with delete[].
This helper is only available when C++11 support is enabled, as it relies on std::unique_ptr. It is intended for the common case where an interface or other marshallable object uses RAII ownership, but the allocation and destruction must still happen on the same heap.
Members
Constructors
The helper is default-constructible and copyable. Copying the deleter shares ownership of the internal reference-counted helper object, so all copies delete through the same originating assembly.
Function operator
Calling the function operator deletes the supplied pointer using the appropriate delete expression for the specialization being used.
Usage
Use MarshallableDelete as the deleter argument for std::unique_ptr when returning ownership of marshallable objects across a module boundary.
std::unique_ptr<IPalette, cobalt::marshalling::MarshallableDelete<IPalette>> CreatePaletteObject();