xrpld
Loading...
Searching...
No Matches
xrpl::SlabAllocator< Type > Class Template Reference

#include <SlabAllocator.h>

Collaboration diagram for xrpl::SlabAllocator< Type >:

Classes

struct  SlabBlock
 A block of memory that is owned by a slab allocator. More...

Public Member Functions

constexpr SlabAllocator (std::size_t extra, std::size_t alloc=0, std::size_t align=0)
 Constructs a slab allocator able to allocate objects of a fixed size.
 SlabAllocator (SlabAllocator const &other)=delete
SlabAllocatoroperator= (SlabAllocator const &other)=delete
 SlabAllocator (SlabAllocator &&other)=delete
SlabAllocatoroperator= (SlabAllocator &&other)=delete
 ~SlabAllocator ()=default
constexpr std::size_t size () const noexcept
 Returns the size of the memory block this allocator returns.
std::uint8_tallocate () noexcept
 Returns a suitably aligned pointer, if one is available.
bool deallocate (std::uint8_t *ptr) noexcept
 Returns the memory block to the allocator.

Private Attributes

std::atomic< SlabBlock * > slabs_ = nullptr
std::size_t const itemAlignment_
std::size_t const itemSize_
std::size_t const slabSize_

Detailed Description

template<typename Type>
class xrpl::SlabAllocator< Type >

Definition at line 27 of file SlabAllocator.h.

Constructor & Destructor Documentation

◆ SlabAllocator() [1/3]

template<typename Type>
xrpl::SlabAllocator< Type >::SlabAllocator ( std::size_t extra,
std::size_t alloc = 0,
std::size_t align = 0 )
explicitconstexpr

Constructs a slab allocator able to allocate objects of a fixed size.

Parameters
countthe number of items the slab allocator can allocate; note that a count of 0 is valid and means that the allocator is, effectively, disabled. This can be very useful in some contexts (e.g. when minimal memory usage is needed) and allows for graceful failure.

Definition at line 155 of file SlabAllocator.h.

◆ SlabAllocator() [2/3]

template<typename Type>
xrpl::SlabAllocator< Type >::SlabAllocator ( SlabAllocator< Type > const & other)
delete

◆ SlabAllocator() [3/3]

template<typename Type>
xrpl::SlabAllocator< Type >::SlabAllocator ( SlabAllocator< Type > && other)
delete

◆ ~SlabAllocator()

template<typename Type>
xrpl::SlabAllocator< Type >::~SlabAllocator ( )
default

Member Function Documentation

◆ operator=() [1/2]

template<typename Type>
SlabAllocator & xrpl::SlabAllocator< Type >::operator= ( SlabAllocator< Type > const & other)
delete

◆ operator=() [2/2]

template<typename Type>
SlabAllocator & xrpl::SlabAllocator< Type >::operator= ( SlabAllocator< Type > && other)
delete

◆ size()

template<typename Type>
std::size_t xrpl::SlabAllocator< Type >::size ( ) const
nodiscardconstexprnoexcept

Returns the size of the memory block this allocator returns.

Definition at line 183 of file SlabAllocator.h.

◆ allocate()

template<typename Type>
std::uint8_t * xrpl::SlabAllocator< Type >::allocate ( )
noexcept

Returns a suitably aligned pointer, if one is available.

Returns
a pointer to a block of memory from the allocator, or nullptr if the allocator can't satisfy this request.

Definition at line 194 of file SlabAllocator.h.

◆ deallocate()

template<typename Type>
bool xrpl::SlabAllocator< Type >::deallocate ( std::uint8_t * ptr)
noexcept

Returns the memory block to the allocator.

Parameters
ptrA pointer to a memory block.
sizeIf non-zero, a hint as to the size of the block.
Returns
true if this memory block belonged to the allocator and has been released; false otherwise.

Definition at line 260 of file SlabAllocator.h.

Member Data Documentation

◆ slabs_

template<typename Type>
std::atomic<SlabBlock*> xrpl::SlabAllocator< Type >::slabs_ = nullptr
private

Definition at line 134 of file SlabAllocator.h.

◆ itemAlignment_

template<typename Type>
std::size_t const xrpl::SlabAllocator< Type >::itemAlignment_
private

Definition at line 137 of file SlabAllocator.h.

◆ itemSize_

template<typename Type>
std::size_t const xrpl::SlabAllocator< Type >::itemSize_
private

Definition at line 141 of file SlabAllocator.h.

◆ slabSize_

template<typename Type>
std::size_t const xrpl::SlabAllocator< Type >::slabSize_
private

Definition at line 144 of file SlabAllocator.h.