KTL
ktl::linear_allocator< Size > Class Template Reference

A linear allocator which gives out chunks of its internal stack. Increments a counter during allocation, which makes it very fast but also unlikely to deallocate it again. Has a max allocation size of the Size given. More...

#include <linear_allocator.h>

Public Member Functions

 linear_allocator () noexcept
 
 linear_allocator (const linear_allocator &) noexcept=delete
 
 linear_allocator (linear_allocator &&other) noexcept
 Move constructor. More...
 
linear_allocatoroperator= (const linear_allocator &) noexcept=delete
 
linear_allocatoroperator= (linear_allocator &&rhs) noexcept
 Move assignment operator. More...
 
bool operator== (const linear_allocator &rhs) const noexcept
 
bool operator!= (const linear_allocator &rhs) const noexcept
 
void * allocate (size_t n) noexcept
 Attempts to allocate a chunk of memory defined by n. More...
 
void deallocate (void *p, size_t n) noexcept
 Attempts to deallocate the memory at location p. More...
 
size_t max_size () const noexcept
 Returns the maximum size that an allocation can be. More...
 
bool owns (void *p) const noexcept
 Returns whether or not the allocator owns the given location in memory. More...
 

Detailed Description

template<size_t Size>
class ktl::linear_allocator< Size >

A linear allocator which gives out chunks of its internal stack. Increments a counter during allocation, which makes it very fast but also unlikely to deallocate it again. Has a max allocation size of the Size given.

Constructor & Destructor Documentation

◆ linear_allocator() [1/3]

template<size_t Size>
ktl::linear_allocator< Size >::linear_allocator ( )
inlinenoexcept

◆ linear_allocator() [2/3]

template<size_t Size>
ktl::linear_allocator< Size >::linear_allocator ( const linear_allocator< Size > &  )
deletenoexcept

◆ linear_allocator() [3/3]

template<size_t Size>
ktl::linear_allocator< Size >::linear_allocator ( linear_allocator< Size > &&  other)
inlinenoexcept

Move constructor.

Note
Moving is only allowed if the original allocator has no allocations
Parameters
otherThe original allocator

Member Function Documentation

◆ allocate()

template<size_t Size>
void* ktl::linear_allocator< Size >::allocate ( size_t  n)
inlinenoexcept

Attempts to allocate a chunk of memory defined by n.

Parameters
nThe amount of bytes to allocate memory for
Returns
A location in memory that is at least n bytes big or nullptr if it could not be allocated

◆ deallocate()

template<size_t Size>
void ktl::linear_allocator< Size >::deallocate ( void *  p,
size_t  n 
)
inlinenoexcept

Attempts to deallocate the memory at location p.

Note
The memory is only completely deallocated if it was the last allocation made or all memory has been deallocated
Parameters
pThe location in memory to deallocate
nThe size that was initially allocated

◆ max_size()

template<size_t Size>
size_t ktl::linear_allocator< Size >::max_size ( ) const
inlinenoexcept

Returns the maximum size that an allocation can be.

Returns
The maximum size an allocation may be

◆ operator!=()

template<size_t Size>
bool ktl::linear_allocator< Size >::operator!= ( const linear_allocator< Size > &  rhs) const
inlinenoexcept

◆ operator=() [1/2]

template<size_t Size>
linear_allocator& ktl::linear_allocator< Size >::operator= ( const linear_allocator< Size > &  )
deletenoexcept

◆ operator=() [2/2]

template<size_t Size>
linear_allocator& ktl::linear_allocator< Size >::operator= ( linear_allocator< Size > &&  rhs)
inlinenoexcept

Move assignment operator.

Note
Moving is only allowed if the original allocator has no allocations
Parameters
rhsThe original allocator

◆ operator==()

template<size_t Size>
bool ktl::linear_allocator< Size >::operator== ( const linear_allocator< Size > &  rhs) const
inlinenoexcept

◆ owns()

template<size_t Size>
bool ktl::linear_allocator< Size >::owns ( void *  p) const
inlinenoexcept

Returns whether or not the allocator owns the given location in memory.

Parameters
pThe location of the object in memory
Returns
Whether the allocator owns p

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