Class thrust::mr::allocator

An mr::allocator is a template that fulfills the C++ requirements for Allocators, allowing to use the NPA-based memory resources where an Allocator is required. Unlike memory resources, but like other allocators, mr::allocator is typed and bound to allocate object of a specific type, however it can be freely rebound to other types.

Template Parameters:

  • T the type that will be allocated by this allocator.
  • MR the upstream memory resource to use for memory allocation. Must derive from thrust::mr::memory_resource and must be final (in C++11 and beyond).

Inherits From: thrust::mr::validator< MR >

#include <thrust/mr/allocator.h>
template <typename T,   class MR> class thrust::mr::allocator { public:  typedef see below void_pointer;
  typedef see below value_type;
  typedef see below pointer;
  typedef see below const_pointer;
  typedef see below reference;
  typedef see below const_reference;
  typedef see below size_type;
  typedef see below difference_type;
  typedef see below propagate_on_container_copy_assignment;
  typedef see below propagate_on_container_move_assignment;
  typedef see below propagate_on_container_swap;
  template <typename U>   struct rebind;
  _CCCL_EXEC_CHECK_DISABLE _CCCL_HOST_DEVICE size_type   max_size() const;
  _CCCL_HOST_DEVICE   allocator(MR * resource);
  template <typename U>   _CCCL_HOST_DEVICE   allocator(const allocator< U, MR > & other);
  _CCCL_NODISCARD _CCCL_HOST pointer   allocate(size_type n);
  _CCCL_HOST void   deallocate(pointer p,     size_type n);
  _CCCL_HOST_DEVICE MR *   resource() const; };

Member Classes

Struct thrust::mr::allocator::rebind

Member Types

Typedef thrust::mr::allocator::void_pointer

typedef MR::pointervoid_pointer; The pointer to void type of this allocator.

Typedef thrust::mr::allocator::value_type

typedef Tvalue_type; The value type allocated by this allocator. Equivalent to T.

Typedef thrust::mr::allocator::pointer

typedef thrust::detail::pointer_traits< void_pointer >::template rebind< T >::otherpointer; The pointer type allocated by this allocator. Equivaled to the pointer type of MR rebound to T.

Typedef thrust::mr::allocator::const_pointer

typedef thrust::detail::pointer_traits< void_pointer >::template rebind< const T >::otherconst_pointer; The pointer to const type. Equivalent to a pointer type of MR rebound to const T.

Typedef thrust::mr::allocator::reference

typedef thrust::detail::pointer_traits< pointer >::referencereference; The reference to the type allocated by this allocator. Supports smart references.

Typedef thrust::mr::allocator::const_reference

typedef thrust::detail::pointer_traits< const_pointer >::referenceconst_reference; The const reference to the type allocated by this allocator. Supports smart references.

Typedef thrust::mr::allocator::size_type

typedef std::size_tsize_type; The size type of this allocator. Always std::size_t.

Typedef thrust::mr::allocator::difference_type

typedef thrust::detail::pointer_traits< pointer >::difference_typedifference_type; The difference type between pointers allocated by this allocator.

Typedef thrust::mr::allocator::propagate_on_container_copy_assignment

typedef detail::true_typepropagate_on_container_copy_assignment; Specifies that the allocator shall be propagated on container copy assignment.

Typedef thrust::mr::allocator::propagate_on_container_move_assignment

typedef detail::true_typepropagate_on_container_move_assignment; Specifies that the allocator shall be propagated on container move assignment.

Typedef thrust::mr::allocator::propagate_on_container_swap

typedef detail::true_typepropagate_on_container_swap; Specifies that the allocator shall be propagated on container swap.

Member Functions

Function thrust::mr::allocator::max_size

_CCCL_EXEC_CHECK_DISABLE _CCCL_HOST_DEVICE size_type max_size() const; Calculates the maximum number of elements allocated by this allocator.

Returns: the maximum value of std::size_t, divided by the size of T.

Function thrust::mr::allocator::allocator

_CCCL_HOST_DEVICE allocator(MR * resource); Constructor.

Function Parameters: resource: the resource to be used to allocate raw memory.

Function thrust::mr::allocator::allocator

template <typename U> _CCCL_HOST_DEVICE allocator(const allocator< U, MR > & other); Copy constructor. Copies the resource pointer.

Function thrust::mr::allocator::allocate

_CCCL_NODISCARD _CCCL_HOST pointer allocate(size_type n); Allocates objects of type T.

Function Parameters: n: number of elements to allocate

Returns: a pointer to the newly allocated storage.

Function thrust::mr::allocator::deallocate

_CCCL_HOST void deallocate(pointer p,   size_type n); Deallocates objects of type T.

Function Parameters:

  • p pointer returned by a previous call to allocate
  • n number of elements, passed as an argument to the allocate call that produced p

Function thrust::mr::allocator::resource

_CCCL_HOST_DEVICE MR * resource() const; Extracts the memory resource used by this allocator.

Returns: the memory resource used by this allocator.