rippled
Loading...
Searching...
No Matches
Classes | Public Member Functions | Private Attributes | List of all members
ripple::SlabAllocator< Type > Class Template Reference

#include <SlabAllocator.h>

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.
 
 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.
 
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 ripple::SlabAllocator< Type >

Definition at line 45 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 182 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 204 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 213 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 224 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 301 of file SlabAllocator.h.

Member Data Documentation

◆ slabs_

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

Definition at line 161 of file SlabAllocator.h.

◆ itemAlignment_

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

Definition at line 164 of file SlabAllocator.h.

◆ itemSize_

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

Definition at line 168 of file SlabAllocator.h.

◆ slabSize_

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

Definition at line 171 of file SlabAllocator.h.