PlayRho  2.0.0
An interactive physics engine & library.
playrho::ThreadLocalAllocator< T, MemoryResource, MemoryResourceArgs > Class Template Reference

Thread local "stateless" allocator. More...

#include <playrho/pmr/ThreadLocalAllocator.hpp>

Public Types

using resource_args = std::tuple< MemoryResourceArgs... >
 Resource argument functors. More...
 
using resource_type = MemoryResource
 Resource type.
 
using value_type = T
 Value type of this class. More...
 

Public Member Functions

 ThreadLocalAllocator ()=default
 Default constructor.
 
template<class U >
 ThreadLocalAllocator (const ThreadLocalAllocator< U, MemoryResource, MemoryResourceArgs... > &)
 Copy constructor.
 
T * allocate (std::size_t n)
 Allocate interface function. More...
 
void deallocate (T *p, std::size_t n)
 Deallocate interface function.
 

Static Public Member Functions

static constexpr auto max_size () noexcept -> std::size_t
 Max size usable by instances of this allocator. More...
 
static PLAYRHO_EXPORT auto resource () -> MemoryResource *
 Gets the underlying memory resource for this class.
 

Friends

bool operator!= (const ThreadLocalAllocator &lhs, const ThreadLocalAllocator &rhs) noexcept
 Inequality support. More...
 
bool operator== (const ThreadLocalAllocator &, const ThreadLocalAllocator &) noexcept
 Equality support. More...
 

Detailed Description

template<class T, class MemoryResource, class... MemoryResourceArgs>
class playrho::ThreadLocalAllocator< T, MemoryResource, MemoryResourceArgs >

Thread local "stateless" allocator.

Note
This is meant to meet the allocator named requirements.
Being a "stateless" allocator, means that objects of this type do not have any non-static data members - i.e. instances themselves don't have any state.
Warning
Behavior is not specified if memory allocated by this class is ever used or deallocated by a different thread.
Template Parameters
Tcv-unqualified object type of each array element that the instantiated allocator will allocate buffers for.
MemoryResourceThe pmr::memory_resource derived type that the instantiated allocator will use to allocate and deallocate buffers from and to.
MemoryResourceArgsZero or more default constructable functor types for passing compile-time arguments for construction of the memory resource object.
See also
https://en.cppreference.com/w/cpp/named_req/Allocator.

Member Typedef Documentation

◆ resource_args

template<class T , class MemoryResource , class... MemoryResourceArgs>
using playrho::ThreadLocalAllocator< T, MemoryResource, MemoryResourceArgs >::resource_args = std::tuple<MemoryResourceArgs...>

Resource argument functors.

This is the list of zero or more types providing arguments for constructing the resource type.

◆ value_type

template<class T , class MemoryResource , class... MemoryResourceArgs>
using playrho::ThreadLocalAllocator< T, MemoryResource, MemoryResourceArgs >::value_type = T

Value type of this class.

Note
This is a required alias of the allocator named requirement.

Member Function Documentation

◆ allocate()

template<class T , class MemoryResource , class... MemoryResourceArgs>
T* playrho::ThreadLocalAllocator< T, MemoryResource, MemoryResourceArgs >::allocate ( std::size_t  n)
inline

Allocate interface function.

Note
Calls underlying resource's allocate function if given size is not too large for this class.
Exceptions
std::bad_array_new_lengthif given a size greater than max_size().

◆ max_size()

template<class T , class MemoryResource , class... MemoryResourceArgs>
static constexpr auto playrho::ThreadLocalAllocator< T, MemoryResource, MemoryResourceArgs >::max_size ( ) -> std::size_t
inlinestaticconstexprnoexcept

Max size usable by instances of this allocator.

Returns
Max value of std::size_t divided by size of this allocator's value type.

Referenced by playrho::ThreadLocalAllocator< T, MemoryResource, MemoryResourceArgs >::allocate().

Friends And Related Function Documentation

◆ operator!=

template<class T , class MemoryResource , class... MemoryResourceArgs>
bool operator!= ( const ThreadLocalAllocator< T, MemoryResource, MemoryResourceArgs > &  lhs,
const ThreadLocalAllocator< T, MemoryResource, MemoryResourceArgs > &  rhs 
)
friend

Inequality support.

Returns
false.

◆ operator==

template<class T , class MemoryResource , class... MemoryResourceArgs>
bool operator== ( const ThreadLocalAllocator< T, MemoryResource, MemoryResourceArgs > &  ,
const ThreadLocalAllocator< T, MemoryResource, MemoryResourceArgs > &   
)
friend

Equality support.

Returns
true.

The documentation for this class was generated from the following file: