thrust::mr::disjoint_synchronized_pool_resource
Defined in thrust/mr/disjoint_sync_pool.h
-
template<typename Upstream, typename Bookkeeper>
struct disjoint_synchronized_pool_resource : public thrust::mr::memory_resource<Upstream::pointer> A mutex-synchronized version of
disjoint_unsynchronized_pool_resource
. Usesstd::mutex
, and therefore requires C++11.- Template Parameters
Upstream – the type of memory resources that will be used for allocating memory blocks to be handed off to the user
Bookkeeper – the type of memory resources that will be used for allocating bookkeeping memory
Public Types
-
using unsync_pool = disjoint_unsynchronized_pool_resource<Upstream, Bookkeeper>
Public Functions
-
inline disjoint_synchronized_pool_resource(Upstream *upstream, Bookkeeper *bookkeeper, pool_options options = get_default_options())
Constructor.
- Parameters
upstream – the upstream memory resource for allocations
bookkeeper – the upstream memory resource for bookkeeping
options – pool options to use
-
inline disjoint_synchronized_pool_resource(pool_options options = get_default_options())
Constructor. Upstream and bookkeeping resources are obtained by calling
get_global_resource
for their types.- Parameters
options – pool options to use
-
inline void release()
Releases all held memory to upstream.
-
inline virtual void_ptr do_allocate(std::size_t bytes, std::size_t alignment = THRUST_MR_DEFAULT_ALIGNMENT) override
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 virtual void do_deallocate(void_ptr p, std::size_t n, std::size_t alignment = THRUST_MR_DEFAULT_ALIGNMENT) override
-
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) noexcept
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 void do_deallocate(pointer p, std::size_t bytes, std::size_t alignment) = 0
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) 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.
Public Static Functions
-
static inline pool_options get_default_options()
Get the default options for a disjoint pool. These are meant to be a sensible set of values for many use cases, and as such, may be tuned in the future. This function is exposed so that creating a set of options that are just a slight departure from the defaults is easy.