thrust::mr::memory_resource#
-
template<typename Pointer = void*>
class memory_resource# memory_resource
is the base class for all other memory resources.- Template Parameters:
Pointer – the pointer type that is allocated and deallocated by the memory resource derived from this base class. If this is
void *
, this class derives fromstd::pmr::memory_resource
.
Subclassed by thrust::mr::new_delete_resource_base, thrust::mr::polymorphic_adaptor_resource< Pointer >
Public Functions
-
virtual ~memory_resource() = default#
Virtual destructor, defaulted when possible.
- inline pointer allocate(
- std::size_t bytes,
- std::size_t alignment = THRUST_MR_DEFAULT_ALIGNMENT,
Allocates memory of size at least
bytes
and alignment at leastalignment
.- Parameters:
bytes – size, in bytes, that is requested from this allocation
alignment – alignment that is requested from this allocation
- Throws:
thrust::bad_alloc – when no memory with requested size and alignment can be allocated.
- Returns:
A pointer to void to the newly allocated memory.
- inline void deallocate(
- pointer p,
- std::size_t bytes,
- std::size_t alignment = THRUST_MR_DEFAULT_ALIGNMENT,
Deallocates memory pointed to by
p
.- Parameters:
p – pointer to be deallocated
bytes – the size of the allocation. This must be equivalent to the value of
bytes
that was passed to the allocation function that returnedp
.alignment – the alignment of the allocation. This must be equivalent to the value of
alignment
that was passed to the allocation function that returnedp
.
-
inline bool is_equal(const memory_resource &other) const noexcept#
Compares this resource to the other one. The default implementation uses identity comparison, which is often the right thing to do and doesn’t require RTTI involvement.
- Parameters:
other – the other resource to compare this resource to
- Returns:
whether the two resources are equivalent.
- virtual pointer do_allocate(
- std::size_t bytes,
- std::size_t alignment,
Allocates memory of size at least
bytes
and alignment at leastalignment
.- Parameters:
bytes – size, in bytes, that is requested from this allocation
alignment – alignment that is requested from this allocation
- Throws:
thrust::bad_alloc – when no memory with requested size and alignment can be allocated.
- Returns:
A pointer to void to the newly allocated memory.
- virtual void do_deallocate(
- pointer p,
- std::size_t bytes,
- std::size_t alignment,
Deallocates memory pointed to by
p
.- Parameters:
p – pointer to be deallocated
bytes – the size of the allocation. This must be equivalent to the value of
bytes
that was passed to the allocation function that returnedp
.alignment – the size of the allocation. This must be equivalent to the value of
alignment
that was passed to the allocation function that returnedp
.
- inline virtual bool do_is_equal(
- const memory_resource &other,
Compares this resource to the other one. The default implementation uses identity comparison, which is often the right thing to do and doesn’t require RTTI involvement.
- Parameters:
other – the other resource to compare this resource to
- Returns:
whether the two resources are equivalent.