维护上游资源生命周期的资源适配器。 更多...
#include <owning_wrapper.hpp>
公共类型 | |
using | upstream_tuple = std::tuple< std::shared_ptr< Upstreams >... > |
上游内存资源的元组。 | |
公共成员函数 | |
template<typename... Args> | |
owning_wrapper (upstream_tuple upstreams, Args &&... args) | |
使用提供的上游资源以及转发给包装资源构造函数的任何额外参数来构造包装资源。 更多... | |
Resource const & | wrapped () const noexcept |
包装资源的常量引用。 更多... | |
Resource & | wrapped () noexcept |
包装资源的引用。 更多... | |
![]() | |
device_memory_resource (device_memory_resource const &)=default | |
默认复制构造函数。 | |
device_memory_resource (device_memory_resource &&) noexcept=default | |
默认移动构造函数。 | |
device_memory_resource & | operator= (device_memory_resource const &)=default |
默认复制赋值运算符。 更多... | |
device_memory_resource & | operator= (device_memory_resource &&) noexcept=default |
默认移动赋值运算符。 更多... | |
void * | allocate (std::size_t bytes, cuda_stream_view stream=cuda_stream_view{}) |
分配至少 bytes 大小的内存。 更多... | |
void | deallocate (void *ptr, std::size_t bytes, cuda_stream_view stream=cuda_stream_view{}) |
释放 p 指向的内存。 更多... | |
bool | is_equal (device_memory_resource const &other) const noexcept |
将此资源与另一个资源进行比较。 更多... | |
void * | allocate (std::size_t bytes, std::size_t alignment) |
分配至少 bytes 大小的内存。 更多... | |
void | deallocate (void *ptr, std::size_t bytes, std::size_t alignment) |
释放 p 指向的内存。 更多... | |
void * | allocate_async (std::size_t bytes, std::size_t alignment, cuda_stream_view stream) |
分配至少 bytes 大小的内存。 更多... | |
void * | allocate_async (std::size_t bytes, cuda_stream_view stream) |
分配至少 bytes 大小的内存。 更多... | |
void | deallocate_async (void *ptr, std::size_t bytes, std::size_t alignment, cuda_stream_view stream) |
释放 p 指向的内存。 更多... | |
void | deallocate_async (void *ptr, std::size_t bytes, cuda_stream_view stream) |
释放 p 指向的内存。 更多... | |
bool | operator== (device_memory_resource const &other) const noexcept |
与另一个 device_memory_resource 的比较运算符。 更多... | |
bool | operator!= (device_memory_resource const &other) const noexcept |
与另一个 device_memory_resource 的比较运算符。 更多... | |
维护上游资源生命周期的资源适配器。
许多派生自 device_memory_resource
的类型会从另一个“上游”资源分配内存。例如,pool_memory_resource
从上游资源分配其内存池。通常,资源不拥有其上游资源,因此用户有责任维护上游资源的生命周期。这可能不方便且容易出错,特别是对于具有复杂上游资源(它们本身也可能有上游)的资源而言。
owning_wrapper
通过 std::shared_ptr
对所有上游资源进行共享所有权,从而简化了包装资源(wrapped
)的生命周期管理。
为了方便起见,建议使用 make_owning_wrapper
工厂函数,而不是直接构造 owning_wrapper
。
示例
Resource | 包装资源的类型 |
Upstreams | Resource 使用的上游资源类型的模板参数包 |
|
inline |
使用提供的上游资源以及转发给包装资源构造函数的任何额外参数来构造包装资源。
Resource
要求其构造函数的第一个参数是指向其上游资源的原始指针,顺序与 upstreams
相同,后面是与 args
顺序相同的任何额外参数。
示例
Args | 转发给包装资源构造函数的模板参数包 |
upstreams | 包装资源使用的上游资源的 std::shared_ptr 元组,顺序与 Resource 构造函数期望的相同。 |
args | 转发给包装资源构造函数的函数参数包 |
|
inlinenoexcept |
包装资源的常量引用。
|
inlinenoexcept |
包装资源的引用。