Class thrust::mr::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 from std::pmr::memory_resource.

Inherited By:

#include <thrust/mr/memory_resource.h>
template <typename Pointer = void*> class thrust::mr::memory_resource { public:  typedef see below pointer;
  virtual   ~memory_resource() = default;
  _CCCL_NODISCARD pointer   allocate(std::size_t bytes,     std::size_t alignment = alignof(std::max_align_t));
  void   deallocate(pointer p,     std::size_t bytes,     std::size_t alignment = alignof(std::max_align_t));
  _CCCL_HOST_DEVICE bool   is_equal(const memory_resource & other) const;
  virtual pointer   do_allocate(std::size_t bytes,     std::size_t alignment) = 0;
  virtual void   do_deallocate(pointer p,     std::size_t bytes,     std::size_t alignment) = 0;
  virtual _CCCL_HOST_DEVICE bool   do_is_equal(const memory_resource & other) const; };

Member Types

Typedef thrust::mr::memory_resource::pointer

typedef Pointerpointer; Alias for the template parameter.

Member Functions

Function thrust::mr::memory_resource::~memory_resource

virtual ~memory_resource() = default; Virtual destructor, defaulted when possible.

Function thrust::mr::memory_resource::allocate

_CCCL_NODISCARD pointer allocate(std::size_t bytes,   std::size_t alignment = alignof(std::max_align_t)); Allocates memory of size at least bytes and alignment at least alignment.

Function Parameters:

  • bytes size, in bytes, that is requested from this allocation
  • alignment alignment that is requested from this allocation

Returns: A pointer to void to the newly allocated memory.

Exceptions: thrust::bad_alloc: when no memory with requested size and alignment can be allocated.

Function thrust::mr::memory_resource::deallocate

void deallocate(pointer p,   std::size_t bytes,   std::size_t alignment = alignof(std::max_align_t)); Deallocates memory pointed to by p.

Function 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 returned p.
  • alignment the alignment of the allocation. This must be equivalent to the value of alignment that was passed to the allocation function that returned p.

Function thrust::mr::memory_resource::is_equal

_CCCL_HOST_DEVICE bool is_equal(const memory_resource & other) const; 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.

Function Parameters: other: the other resource to compare this resource to

Returns: whether the two resources are equivalent.

Function thrust::mr::memory_resource::do_allocate

virtual pointer do_allocate(std::size_t bytes,   std::size_t alignment) = 0; Allocates memory of size at least bytes and alignment at least alignment.

Function Parameters:

  • bytes size, in bytes, that is requested from this allocation
  • alignment alignment that is requested from this allocation

Returns: A pointer to void to the newly allocated memory.

Exceptions: thrust::bad_alloc: when no memory with requested size and alignment can be allocated.

Implemented By:

Function thrust::mr::memory_resource::do_deallocate

virtual void do_deallocate(pointer p,   std::size_t bytes,   std::size_t alignment) = 0; Deallocates memory pointed to by p.

Function 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 returned p.
  • alignment the size of the allocation. This must be equivalent to the value of alignment that was passed to the allocation function that returned p.

Implemented By:

Function thrust::mr::memory_resource::do_is_equal

virtual _CCCL_HOST_DEVICE bool do_is_equal(const memory_resource & other) const; 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.

Function Parameters: other: the other resource to compare this resource to

Returns: whether the two resources are equivalent.