template<auto deallocator>
class ResourceCleanup::Attorney< deallocator >
Attorney for a resource deallocator.
Usage:
#include <thrust/device_free.h>
#include <thrust/device_malloc.h>
#include <memory>
class MyClass;
static std::shared_ptr<ResourceCleanup> resource_queue = nullptr;
static std::shared_ptr<MyClass> resource = nullptr;
class MyClass {
private:
thrust::device_ptr<float> data_dev;
void free_device_memory() { thrust::device_free(data_dev); }
friend Cleanup;
public:
MyClass(int n) { data_dev = thrust::device_malloc<float>(n); }
~MyClass() { free_device_memory(); }
template <class... Args>
static auto make_shared(Args ...args) {
auto obj = std::make_shared<MyClass>(args...);
::resource_queue->push<MyClass::Cleanup>(obj);
return obj;
}
};
::resource_queue = std::make_shared<ResourceCleanup>();
::resource = MyClass::make_shared(5);
::resource_queue.reset();
}
Attorney for a resource deallocator.
- Template Parameters
-
deallocator | Member function that deallocates managed resources. |
Definition at line 106 of file ResourceCleanup.hpp.