rippled
Classes | Public Member Functions | Private Attributes | List of all members
ripple::SlabAllocator< Type > Class Template Reference
Collaboration diagram for ripple::SlabAllocator< Type >:
Collaboration graph
[legend]

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. More...
 
 SlabAllocator (SlabAllocator const &other)=delete
 
SlabAllocatoroperator= (SlabAllocator const &other)=delete
 
 SlabAllocator (SlabAllocator &&other)=delete
 
SlabAllocatoroperator= (SlabAllocator &&other)=delete
 
 ~SlabAllocator ()
 
constexpr std::size_t size () const noexcept
 Returns the size of the memory block this allocator returns. More...
 
std::uint8_tallocate () noexcept
 Returns a suitably aligned pointer, if one is available. More...
 
bool deallocate (std::uint8_t *ptr) noexcept
 Returns the memory block to the allocator. More...
 

Private Attributes

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

Detailed Description

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

Definition at line 43 of file SlabAllocator.h.

Constructor & Destructor Documentation

◆ SlabAllocator() [1/3]

template<typename Type >
constexpr ripple::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 mimimal memory usage is needed) and allows for graceful failure.

Definition at line 178 of file SlabAllocator.h.

◆ SlabAllocator() [2/3]

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

◆ SlabAllocator() [3/3]

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

◆ ~SlabAllocator()

template<typename Type >
ripple::SlabAllocator< Type >::~SlabAllocator ( )

Definition at line 198 of file SlabAllocator.h.

Member Function Documentation

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ size()

template<typename Type >
constexpr std::size_t ripple::SlabAllocator< Type >::size ( ) const
constexprnoexcept

Returns the size of the memory block this allocator returns.

Definition at line 207 of file SlabAllocator.h.

◆ allocate()

template<typename Type >
std::uint8_t* ripple::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 218 of file SlabAllocator.h.

◆ deallocate()

template<typename Type >
bool ripple::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 295 of file SlabAllocator.h.

Member Data Documentation

◆ slabs_

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

Definition at line 157 of file SlabAllocator.h.

◆ itemAlignment_

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

Definition at line 160 of file SlabAllocator.h.

◆ itemSize_

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

Definition at line 164 of file SlabAllocator.h.

◆ slabSize_

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

Definition at line 167 of file SlabAllocator.h.