OnixS C++ CME MDP Premium Market Data Handler 5.11.1
Users' manual and API documentation
Loading...
Searching...
No Matches
MemoryPoolAllocator< Object > Class Template Reference

#include <OnixS/CME/MDH/MemoryPool.h>

Classes

struct  rebind

Public Types

using value_type = Object
using pointer = Object*
using const_pointer = const Object*
using reference = Object&
using const_reference = const Object&
using size_type = std::size_t
using difference_type = std::ptrdiff_t

Public Member Functions

 MemoryPoolAllocator () noexcept
 MemoryPoolAllocator (MemoryPool &memoryPool) noexcept
 MemoryPoolAllocator (const MemoryPoolAllocator &other) noexcept=default
template<class Other>
 MemoryPoolAllocator (const MemoryPoolAllocator< Other > &other) noexcept
 ~MemoryPoolAllocator () noexcept=default
MemoryPool & memoryPool () const noexcept
pointer address (reference obj) const noexcept
const_pointer address (const_reference x) const noexcept
pointer allocate (size_type qty)
void deallocate (pointer block, size_type qty) noexcept
template<class Item, class... Args>
void construct (Item *block, Args &&... args)
void destroy (pointer obj) noexcept
size_type max_size () const noexcept
MemoryPoolAllocator & operator= (const MemoryPoolAllocator &other) noexcept=default
template<class Other>
MemoryPoolAllocator & operator= (const MemoryPoolAllocator< Other > &other) noexcept

Friends

template<class>
class MemoryPoolAllocator
template<class LeftObject, class RightObject>
bool operator== (const MemoryPoolAllocator< LeftObject > &left, const MemoryPoolAllocator< RightObject > &right) noexcept

Detailed Description

template<class Object>
class OnixS::CME::MDH::MemoryPoolAllocator< Object >
Template Parameters
ObjectObject type allocated by this adapter. Allocation requires alignment no greater than alignof(std::max_align_t).

The adapter holds a non-owning pointer to its pool. The pool must outlive the allocator and every container or allocation that uses it.

Definition at line 102 of file MemoryPool.h.

Member Typedef Documentation

◆ const_pointer

template<class Object>
using const_pointer = const Object*

Read-only pointer to an allocated object.

Definition at line 112 of file MemoryPool.h.

◆ const_reference

template<class Object>
using const_reference = const Object&

Read-only reference to an allocated object.

Definition at line 118 of file MemoryPool.h.

◆ difference_type

template<class Object>
using difference_type = std::ptrdiff_t

Signed type used for pointer differences.

Definition at line 124 of file MemoryPool.h.

◆ pointer

template<class Object>
using pointer = Object*

Mutable pointer to an allocated object.

Definition at line 109 of file MemoryPool.h.

◆ reference

template<class Object>
using reference = Object&

Mutable reference to an allocated object.

Definition at line 115 of file MemoryPool.h.

◆ size_type

template<class Object>
using size_type = std::size_t

Unsigned type used for object counts.

Definition at line 121 of file MemoryPool.h.

◆ value_type

template<class Object>
using value_type = Object

Type of object allocated by this adapter.

Definition at line 106 of file MemoryPool.h.

Constructor & Destructor Documentation

◆ MemoryPoolAllocator() [1/4]

template<class Object>
MemoryPoolAllocator ( )
inlinenoexcept

Creates an allocator that is not associated with a pool.

Note
Associate the allocator with a pool before calling memoryPool(), allocate(), or deallocate().

Definition at line 138 of file MemoryPool.h.

◆ MemoryPoolAllocator() [2/4]

template<class Object>
MemoryPoolAllocator ( MemoryPool & memoryPool)
inlinenoexcept

Associates the allocator with a pool.

Parameters
memoryPoolPool used for subsequent allocations and deallocations.
Note
The allocator does not take ownership of memoryPool.

Definition at line 146 of file MemoryPool.h.

◆ MemoryPoolAllocator() [3/4]

template<class Object>
MemoryPoolAllocator ( const MemoryPoolAllocator< Object > & other)
defaultnoexcept

Copies the source allocator's pool association.

Parameters
otherSource allocator.

◆ MemoryPoolAllocator() [4/4]

template<class Object>
template<class Other>
MemoryPoolAllocator ( const MemoryPoolAllocator< Other > & other)
inlinenoexcept

Copies a compatible allocator's pool association.

Template Parameters
OtherObject type allocated by the source allocator.
Parameters
otherSource allocator.

Definition at line 159 of file MemoryPool.h.

◆ ~MemoryPoolAllocator()

template<class Object>
~MemoryPoolAllocator ( )
defaultnoexcept

Destroys the adapter without releasing its pool or outstanding storage.

Member Function Documentation

◆ address() [1/2]

template<class Object>
const_pointer address ( const_reference x) const
inlinenoexcept

Obtains the address of a read-only object.

Parameters
xObject whose address is requested.
Returns
Pointer to x.

Definition at line 189 of file MemoryPool.h.

◆ address() [2/2]

template<class Object>
pointer address ( reference obj) const
inlinenoexcept

Obtains the address of a mutable object.

Parameters
objObject whose address is requested.
Returns
Pointer to obj.

Definition at line 180 of file MemoryPool.h.

◆ allocate()

template<class Object>
pointer allocate ( size_type qty)
inline

Allocates uninitialized storage for a sequence of objects.

Parameters
qtyNumber of objects for which storage is required.
Returns
Pointer to the beginning of the allocated storage.
Exceptions
std::length_errorIf qty exceeds max_size(), or if the resulting allocation or configured chunk is too large.
std::bad_allocIf storage cannot be allocated.
Precondition
This allocator is associated with a pool.
Note
value_type must not require extended alignment.

Definition at line 203 of file MemoryPool.h.

◆ construct()

template<class Object>
template<class Item, class... Args>
void construct ( Item * block,
Args &&... args )
inline

Constructs an object in allocated storage.

Template Parameters
ItemObject type to construct.
ArgsConstructor argument types.
Parameters
blockAddress of suitably aligned uninitialized storage.
argsArguments forwarded to the object's constructor.
Exceptions
Anyexception thrown by the selected constructor.

Definition at line 239 of file MemoryPool.h.

◆ deallocate()

template<class Object>
void deallocate ( pointer block,
size_type qty )
inlinenoexcept

Returns storage to the associated pool.

Parameters
blockPointer returned by allocate(), or nullptr.
qtyObject count supplied for allocator compatibility; it is not inspected.
Precondition
This allocator is associated with a pool.
A non-null block was allocated by the associated pool.

Definition at line 223 of file MemoryPool.h.

◆ destroy()

template<class Object>
void destroy ( pointer obj)
inlinenoexcept

Destroys an object without deallocating its storage.

Parameters
objObject previously constructed in allocated storage.
Note
value_type must be nothrow-destructible.

Definition at line 247 of file MemoryPool.h.

◆ max_size()

template<class Object>
size_type max_size ( ) const
inlinenoexcept

Computes the largest object count representable as a byte size.

Returns
Maximum count that can be multiplied by sizeof(value_type) without overflow.

Definition at line 261 of file MemoryPool.h.

◆ memoryPool()

template<class Object>
MemoryPool & memoryPool ( ) const
inlinenoexcept

Accesses the associated pool.

Returns
Reference to the pool used by this allocator.
Precondition
This allocator is associated with a pool.

Definition at line 171 of file MemoryPool.h.

◆ operator=() [1/2]

template<class Object>
MemoryPoolAllocator & operator= ( const MemoryPoolAllocator< Object > & other)
defaultnoexcept

Replaces this allocator's pool association with the source association.

Parameters
otherSource allocator.
Returns
Reference to this allocator.

◆ operator=() [2/2]

template<class Object>
template<class Other>
MemoryPoolAllocator & operator= ( const MemoryPoolAllocator< Other > & other)
inlinenoexcept

Replaces this allocator's pool association with a compatible source association.

Template Parameters
OtherObject type allocated by the source allocator.
Parameters
otherSource allocator.
Returns
Reference to this allocator.

Definition at line 276 of file MemoryPool.h.

◆ MemoryPoolAllocator

template<class Object>
template<class>
friend class MemoryPoolAllocator
friend

Definition at line 284 of file MemoryPool.h.

◆ operator==

template<class Object>
template<class LeftObject, class RightObject>
bool operator== ( const MemoryPoolAllocator< LeftObject > & left,
const MemoryPoolAllocator< RightObject > & right )
friend