Utility class to store an arbitrary type-erased object while another object is alive. More...
#include <owning_wrapper.hpp>
Public Types | |
| using | deleter_type = void(*)(void *) |
| Callback used to delete the owned object. | |
Public Member Functions | |
| OwningWrapper (void *obj, deleter_type deleter) | |
| Take ownership and responsibility for the destruction of an object. More... | |
| void * | release () noexcept |
| Release ownership of the underlying pointer. More... | |
| void * | get () const noexcept |
Utility class to store an arbitrary type-erased object while another object is alive.
When sending messages through Channels from Python, we typically need to keep various Python objects alive since the matching C++ objects only hold views.
For example, when constructing a TableChunk from a pylibcudf Table, the TableChunk has a non-owning cudf::table_view of the Table and someone must be responsible for keeping the Table alive for the lifetime of the TableChunk. If we want to allow creation of such objects in Python with the ability to sink them on the C++ side we cannot rely on the Python side of things keeping the Table alive (the reference disappears!). Similarly when we send a message through a Channel the sender will, once pushed into the channel, drop the reference to the message payload and so, again, we need some way of keeping the payload alive.
To square this circle, such C++ objects have an OwningWrapper slot that stores a type-erased pointer with, as far as we are concerned, unique ownership semantics. When this object is destroyed, the custom deleter runs and can do whatever deallocation is necessary.
std::terminate.OwningWrapper inside a C++ object, make sure it is constructed first and destructed last. Definition at line 42 of file owning_wrapper.hpp.
|
inlineexplicit |
Take ownership and responsibility for the destruction of an object.
| obj | Type-erased object to own. |
| deleter | Function called to destruct the object. |
Definition at line 55 of file owning_wrapper.hpp.
|
inlinenoexcept |
Definition at line 70 of file owning_wrapper.hpp.
|
inlinenoexcept |
Release ownership of the underlying pointer.
Definition at line 63 of file owning_wrapper.hpp.