ecor
Loading...
Searching...
No Matches
ecor::circular_buffer_allocator< T, IndexType, Base > Struct Template Reference

Allocator that uses reference to circular_buffer_memory for allocating memory. More...

#include <ecor.hpp>

Classes

struct  rebind
 

Public Types

using difference_type = std::ptrdiff_t
 
using size_type = std::size_t
 
using value_type = T
 

Public Member Functions

T * allocate (std::size_t n)
 Allocate memory for n objects of type T, returns pointer to the allocated memory. More...
 
 circular_buffer_allocator (circular_buffer_allocator const &) noexcept=default
 Copy constructor, allows copying the allocator. More...
 
template<typename U >
 circular_buffer_allocator (circular_buffer_allocator< U, IndexType, Base > const &other) noexcept
 Template copy constructor, allows copying from an allocator of a different type. More...
 
 circular_buffer_allocator (circular_buffer_memory< IndexType, Base > &buffer) noexcept
 Construct an allocator that uses the given circular_buffer_memory for allocations.
 
void deallocate (T *ptr, std::size_t n)
 Deallocate memory previously allocated by allocate(). More...
 
bool operator!= (circular_buffer_allocator const &other) const noexcept
 Inequality comparison operator, defined in terms of operator==.
 
bool operator== (circular_buffer_allocator const &other) const noexcept
 Equality comparison operators, allocators are equal if they refer to the same circular_buffer_memory.
 

Friends

template<typename U , typename IdxType , typename Base2 >
struct circular_buffer_allocator
 Grant access to other allocator types for copying. More...
 

Detailed Description

template<typename T, typename IndexType, typename Base>
struct ecor::circular_buffer_allocator< T, IndexType, Base >

Allocator that uses reference to circular_buffer_memory for allocating memory.

This can be used to create standard library containers that use circular_buffer_memory for their allocations.

The template parameters are:

Constructor & Destructor Documentation

◆ circular_buffer_allocator() [1/2]

template<typename T , typename IndexType , typename Base >
ecor::circular_buffer_allocator< T, IndexType, Base >::circular_buffer_allocator ( circular_buffer_allocator< T, IndexType, Base > const &  )
defaultnoexcept

Copy constructor, allows copying the allocator.

The copied allocator will refer to the same circular_buffer_memory.

◆ circular_buffer_allocator() [2/2]

template<typename T , typename IndexType , typename Base >
template<typename U >
ecor::circular_buffer_allocator< T, IndexType, Base >::circular_buffer_allocator ( circular_buffer_allocator< U, IndexType, Base > const &  other)
inlinenoexcept

Template copy constructor, allows copying from an allocator of a different type.

The copied allocator will refer to the same circular_buffer_memory.

Member Function Documentation

◆ allocate()

template<typename T , typename IndexType , typename Base >
T * ecor::circular_buffer_allocator< T, IndexType, Base >::allocate ( std::size_t  n)
inline

Allocate memory for n objects of type T, returns pointer to the allocated memory.

The memory is allocated from the circular_buffer_memory associated with this allocator. The returned pointer is valid until the memory resource is destroyed or the memory is deallocated.

Throws std::bad_alloc if allocation fails.

◆ deallocate()

template<typename T , typename IndexType , typename Base >
void ecor::circular_buffer_allocator< T, IndexType, Base >::deallocate ( T *  ptr,
std::size_t  n 
)
inline

Deallocate memory previously allocated by allocate().

The pointer must have been returned by a previous call to allocate() on this allocator, and the size n must match the size used in that call. The memory is deallocated back to the circular_buffer_memory associated with this allocator.

Friends And Related Function Documentation

◆ circular_buffer_allocator

template<typename T , typename IndexType , typename Base >
template<typename U , typename IdxType , typename Base2 >
friend struct circular_buffer_allocator
friend

Grant access to other allocator types for copying.

This allows allocators of different types to access each other's internal buffer pointer when copying.


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