fennec
Loading...
Searching...
No Matches
fennec::allocation< T, AllocT >

Container to hold a memory allocation. More...

#include <allocator.h>

Collaboration diagram for fennec::allocation< T, AllocT >:
[legend]

Detailed Description

template<typename T, class AllocT = allocator<T>>
struct fennec::allocation< T, AllocT >
Template Parameters
TThe data type of the allocation

This simply acts as a proxy for allocating memory. It does not call any constructors or initialize any values as if they were the provided data type. Any operations present work only on individual bytes.

Public Types

using alloc_t = typename allocator_traits< AllocT >::template rebind< T >
 alias for the allocator type
 
using value_t = T
 alias for the data type
 
using size_t = size_t
 size type definition for ptr_traits
 
using diff_t = ptrdiff_t
 diff type definition for ptr_traits
 

Public Member Functions

constexpr allocation () noexcept
 Default Constructor, initializes internal data to null and the capacity to 0
 
constexpr allocation (size_t n) noexcept
 Sized Constructor, initializes the allocation with a block of size n * sizeof(T) bytes.
 
constexpr allocation (const T *data, size_t n)
 Buffer Copy Constructor, initializes the allocation with a block of size n * sizeof(T) bytes. Then, the contents of data are byte copied into the allocation.
 
constexpr allocation (size_t n, align_t align) noexcept
 Sized Constructor, initializes the allocation with a block of size n * sizeof(T) bytes.
 
constexpr allocation (const T *data, size_t n, align_t align)
 Buffer Copy Constructor, initializes the allocation with a block of size n * sizeof(T) bytes. Then, the contents of data are byte copied into the allocation.
 
constexpr allocation (const alloc_t &alloc) noexcept
 Allocator Constructor.
 
constexpr allocation (size_t n, const alloc_t &alloc) noexcept
 Sized Allocator Constructor.
 
constexpr allocation (const T *data, size_t n, const alloc_t &alloc)
 Buffer Copy Allocator Constructor, initializes the allocation with a block of size n * sizeof(T) bytes. Then, the contents of data are copied into the allocation.
 
constexpr allocation (size_t n, align_t align, const alloc_t &alloc) noexcept
 Sized Allocator Constructor.
 
constexpr allocation (const T *data, size_t n, align_t align, const alloc_t &alloc)
 Buffer Copy Allocator Constructor, initializes the allocation with a block of size n * sizeof(T) bytes. Then, the contents of data are copied into the allocation.
 
constexpr allocation (const allocation &alloc) noexcept
 Copy Constructor, creates an allocation of equal size and performs a byte-wise copy.
 
constexpr allocation (allocation &&alloc) noexcept
 Move Constructor, moves the data in alloc to the new object and cleans alloc so that it can safely destruct.
 
constexpr ~allocation () noexcept
 Default Destructor, releases the memory block if still present.
 
constexpr allocationoperator= (const allocation &alloc)
 Copy Assignment Operator.
 
constexpr allocationoperator= (allocation &&alloc) noexcept
 Move Assignment Operator.
 
constexpr void allocate (size_t n, align_t align=zero< align_t >()) noexcept
 Allocate a block of memory for the allocation. If there is already an allocated block of memory, the previous allocation is released.
 
constexpr void callocate (size_t n, align_t align=zero< align_t >()) noexcept
 Allocate a block of memory for the allocation. If there is already an allocated block of memory, the previous allocation is released.
 
constexpr void deallocate () noexcept
 Release the block of memory.
 
constexpr void reallocate (size_t n, align_t align=zero< align_t >()) noexcept
 Reallocate the block with a new size. Contents are copied to the new allocation.
 
constexpr void creallocate (size_t n, align_t align=zero< align_t >()) noexcept
 Reallocate the block with a new size. Contents are copied to the new allocation.
 
constexpr void clear () noexcept
 Clear the block of memory, setting all bytes to 0.
 
constexpr size_t size () const
 Getter for the byte size of the allocation.
 
constexpr size_t capacity () const
 Getter for the number of elements n of type T that the allocation can hold.
 
constexpr value_tdata ()
 Getter for the real pointer to the allocated block of memory.
 
constexpr const value_tdata () const
 Getter for the real pointer to the allocated block of memory.
 

Constructor & Destructor Documentation

◆ allocation() [1/11]

template<typename T , class AllocT = allocator<T>>
constexpr fennec::allocation< T, AllocT >::allocation ( size_t  n)
inlineexplicitconstexprnoexcept
Parameters
nThe number of elements of type T to allocate for

◆ allocation() [2/11]

template<typename T , class AllocT = allocator<T>>
constexpr fennec::allocation< T, AllocT >::allocation ( const T *  data,
size_t  n 
)
inlineconstexpr
Parameters
datathe buffer to copy
nthe number of elements

◆ allocation() [3/11]

template<typename T , class AllocT = allocator<T>>
constexpr fennec::allocation< T, AllocT >::allocation ( size_t  n,
align_t  align 
)
inlineconstexprnoexcept
Parameters
nThe number of elements of type T to allocate for
alignThe alignment of the allocation

◆ allocation() [4/11]

template<typename T , class AllocT = allocator<T>>
constexpr fennec::allocation< T, AllocT >::allocation ( const T *  data,
size_t  n,
align_t  align 
)
inlineconstexpr
Parameters
datathe buffer to copy
nthe number of elements
alignThe alignment of the allocation

◆ allocation() [5/11]

template<typename T , class AllocT = allocator<T>>
constexpr fennec::allocation< T, AllocT >::allocation ( const alloc_t alloc)
inlineexplicitconstexprnoexcept
Parameters
allocThe allocation object to copy.

This constructor should be used when the type AllocT needs internal data.

◆ allocation() [6/11]

template<typename T , class AllocT = allocator<T>>
constexpr fennec::allocation< T, AllocT >::allocation ( size_t  n,
const alloc_t alloc 
)
inlineconstexprnoexcept
Parameters
nThe number of elements of type T to allocate for
allocThe allocation object to copy.

This constructor should be used when the type AllocT needs internal data.

◆ allocation() [7/11]

template<typename T , class AllocT = allocator<T>>
constexpr fennec::allocation< T, AllocT >::allocation ( const T *  data,
size_t  n,
const alloc_t alloc 
)
inlineconstexpr
Parameters
datathe buffer to copy
nthe number of elements
allocThe allocation object to copy.

This constructor should be used when the type AllocT needs internal data.

◆ allocation() [8/11]

template<typename T , class AllocT = allocator<T>>
constexpr fennec::allocation< T, AllocT >::allocation ( size_t  n,
align_t  align,
const alloc_t alloc 
)
inlineconstexprnoexcept
Parameters
nThe number of elements of type T to allocate for
alignThe alignment of the allocation
allocThe allocation object to copy.

This constructor should be used when the type AllocT needs internal data.

◆ allocation() [9/11]

template<typename T , class AllocT = allocator<T>>
constexpr fennec::allocation< T, AllocT >::allocation ( const T *  data,
size_t  n,
align_t  align,
const alloc_t alloc 
)
inlineconstexpr
Parameters
datathe buffer to copy
nthe number of elements
alignThe alignment of the allocation
allocThe allocation object to copy.

This constructor should be used when the type AllocT needs internal data.

◆ allocation() [10/11]

template<typename T , class AllocT = allocator<T>>
constexpr fennec::allocation< T, AllocT >::allocation ( const allocation< T, AllocT > &  alloc)
inlineconstexprnoexcept
Parameters
allocThe allocation to copy

◆ allocation() [11/11]

template<typename T , class AllocT = allocator<T>>
constexpr fennec::allocation< T, AllocT >::allocation ( allocation< T, AllocT > &&  alloc)
inlineconstexprnoexcept
Parameters
allocThe allocation to move

Member Function Documentation

◆ operator=() [1/2]

template<typename T , class AllocT = allocator<T>>
constexpr allocation & fennec::allocation< T, AllocT >::operator= ( const allocation< T, AllocT > &  alloc)
inlineconstexpr
Parameters
allocthe allocation to copy
Returns
a reference to this

◆ operator=() [2/2]

template<typename T , class AllocT = allocator<T>>
constexpr allocation & fennec::allocation< T, AllocT >::operator= ( allocation< T, AllocT > &&  alloc)
inlineconstexprnoexcept
Parameters
allocthe allocation to copy
Returns
a reference to this

◆ allocate()

template<typename T , class AllocT = allocator<T>>
constexpr void fennec::allocation< T, AllocT >::allocate ( size_t  n,
align_t  align = zero<align_t>() 
)
inlineconstexprnoexcept
Parameters
nThe number of elements of type T to allocate for

◆ callocate()

template<typename T , class AllocT = allocator<T>>
constexpr void fennec::allocation< T, AllocT >::callocate ( size_t  n,
align_t  align = zero<align_t>() 
)
inlineconstexprnoexcept
Parameters
nThe number of elements of type T to allocate for

◆ size()

template<typename T , class AllocT = allocator<T>>
constexpr size_t fennec::allocation< T, AllocT >::size ( ) const
inlineconstexpr
Returns
the size of the allocation in bytes

◆ capacity()

template<typename T , class AllocT = allocator<T>>
constexpr size_t fennec::allocation< T, AllocT >::capacity ( ) const
inlineconstexpr
Returns
the size of the allocation in elements

◆ data() [1/2]

template<typename T , class AllocT = allocator<T>>
constexpr value_t * fennec::allocation< T, AllocT >::data ( )
inlineconstexpr
Returns
Pointer to the allocated memory.

◆ data() [2/2]

template<typename T , class AllocT = allocator<T>>
constexpr const value_t * fennec::allocation< T, AllocT >::data ( ) const
inlineconstexpr
Returns
Pointer to the allocated memory.

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