cpp-msgpack-light 0.3.0
A light library to serialize MessagePack.
Loading...
Searching...
No Matches
msgpack_light::monotonic_allocator Class Reference

Class of an allocator which releases memory only when the allocator is destroyed. More...

#include <msgpack_light/monotonic_allocator.h>

Collaboration diagram for msgpack_light::monotonic_allocator:

Public Member Functions

 monotonic_allocator ()
 Constructor.
 monotonic_allocator (const monotonic_allocator &) noexcept
 Copy constructor.
 monotonic_allocator (monotonic_allocator &&other) noexcept
 Move constructor.
 ~monotonic_allocator ()
 Destructor.
void * allocate (std::size_t size, std::size_t alignment)
 Allocate memory.
void deallocate (void *ptr) noexcept
 Deallocate memory.
monotonic_allocatoroperator= (const monotonic_allocator &) noexcept
 Copy assignment operator.
monotonic_allocatoroperator= (monotonic_allocator &&other) noexcept
 Move assignment operator.
void swap (monotonic_allocator &other) noexcept
 Swap with another instance.

Static Public Attributes

static constexpr std::size_t initial_buffer_size = 1024U
 Size of the initial buffer.
static constexpr std::size_t max_allocation_from_buffer = 512U
 Maximum size of memory allocated from buffer.

Private Member Functions

void * allocate_directly (std::size_t size, std::size_t alignment)
 Allocate memory directly using malloc function.
void change_buffer ()
 Prepare the next buffer.
void prepare_buffer ()
 Prepare a buffer.
void * try_allocate_from_buffer (std::size_t size, std::size_t alignment)
 Try to allocate from the current buffer.

Static Private Member Functions

static void * allocate_buffer (std::size_t size)
 Allocate a buffer.

Private Attributes

void * current_buffer_ {nullptr}
 Current buffer.
std::size_t current_buffer_size_ {initial_buffer_size}
 Size of the current buffer.
void * last_direct_allocation_ {nullptr}
 Last pointer to the memory allocated directly using malloc function.
void * next_allocation_point_ {nullptr}
 Pointer to the byte from which the next allocation starts.
std::size_t remaining_buffer_ {initial_buffer_size}
 Remaining size of the current buffer.

Detailed Description

Class of an allocator which releases memory only when the allocator is destroyed.

Definition at line 35 of file monotonic_allocator.h.

Constructor & Destructor Documentation

◆ monotonic_allocator() [1/3]

msgpack_light::monotonic_allocator::monotonic_allocator ( )
inline

Constructor.

Definition at line 46 of file monotonic_allocator.h.

◆ monotonic_allocator() [2/3]

msgpack_light::monotonic_allocator::monotonic_allocator ( const monotonic_allocator & )
inlinenoexcept

Copy constructor.

Note
This simply initialize this instance without any copy.

Definition at line 53 of file monotonic_allocator.h.

◆ monotonic_allocator() [3/3]

msgpack_light::monotonic_allocator::monotonic_allocator ( monotonic_allocator && other)
inlinenoexcept

Move constructor.

Parameters
[in,out]otherInstance to move from.

Definition at line 61 of file monotonic_allocator.h.

◆ ~monotonic_allocator()

msgpack_light::monotonic_allocator::~monotonic_allocator ( )
inline

Destructor.

Definition at line 109 of file monotonic_allocator.h.

Member Function Documentation

◆ allocate()

void * msgpack_light::monotonic_allocator::allocate ( std::size_t size,
std::size_t alignment )
inlinenodiscard

Allocate memory.

Parameters
[in]sizeNumber of bytes to allocate.
[in]alignmentAlignment.
Returns
Pointer to the allocated memory.

Definition at line 131 of file monotonic_allocator.h.

◆ allocate_buffer()

void * msgpack_light::monotonic_allocator::allocate_buffer ( std::size_t size)
inlinestaticnodiscardprivate

Allocate a buffer.

Parameters
[in]sizeSize of the buffer.
Returns
Pointer to the allocated buffer.

Definition at line 166 of file monotonic_allocator.h.

◆ allocate_directly()

void * msgpack_light::monotonic_allocator::allocate_directly ( std::size_t size,
std::size_t alignment )
inlinenodiscardprivate

Allocate memory directly using malloc function.

Parameters
[in]sizeSize.
[in]alignmentAlignment.
Returns
Pointer to the allocated memory.

Definition at line 229 of file monotonic_allocator.h.

◆ change_buffer()

void msgpack_light::monotonic_allocator::change_buffer ( )
inlineprivate

Prepare the next buffer.

Definition at line 177 of file monotonic_allocator.h.

◆ deallocate()

void msgpack_light::monotonic_allocator::deallocate ( void * ptr)
inlinenoexcept

Deallocate memory.

Note
This class does nothing in this function.
Parameters
[in]ptrPointer to the deallocated memory.

Definition at line 154 of file monotonic_allocator.h.

◆ operator=() [1/2]

monotonic_allocator & msgpack_light::monotonic_allocator::operator= ( const monotonic_allocator & )
inlinenoexcept

Copy assignment operator.

Note
This does nothing.
Returns
This instance after copy.

Definition at line 77 of file monotonic_allocator.h.

◆ operator=() [2/2]

monotonic_allocator & msgpack_light::monotonic_allocator::operator= ( monotonic_allocator && other)
inlinenoexcept

Move assignment operator.

Parameters
[in,out]otherInstance to move from.
Returns
This instance after move.

Definition at line 88 of file monotonic_allocator.h.

◆ prepare_buffer()

void msgpack_light::monotonic_allocator::prepare_buffer ( )
inlineprivate

Prepare a buffer.

Note
Call this function after update of current_buffer_size_ to the next size.

Definition at line 193 of file monotonic_allocator.h.

◆ swap()

void msgpack_light::monotonic_allocator::swap ( monotonic_allocator & other)
inlinenoexcept

Swap with another instance.

Parameters
[out]otherAnother instance.

Definition at line 98 of file monotonic_allocator.h.

◆ try_allocate_from_buffer()

void * msgpack_light::monotonic_allocator::try_allocate_from_buffer ( std::size_t size,
std::size_t alignment )
inlinenodiscardprivate

Try to allocate from the current buffer.

Parameters
[in]sizeNumber of bytes to allocate.
[in]alignmentAlignment.
Returns
Pointer to the allocated memory. Null on failure.

Definition at line 209 of file monotonic_allocator.h.

Member Data Documentation

◆ current_buffer_

void* msgpack_light::monotonic_allocator::current_buffer_ {nullptr}
private

Current buffer.

Definition at line 250 of file monotonic_allocator.h.

◆ current_buffer_size_

std::size_t msgpack_light::monotonic_allocator::current_buffer_size_ {initial_buffer_size}
private

Size of the current buffer.

Definition at line 247 of file monotonic_allocator.h.

◆ initial_buffer_size

std::size_t msgpack_light::monotonic_allocator::initial_buffer_size = 1024U
staticconstexpr

Size of the initial buffer.

Definition at line 38 of file monotonic_allocator.h.

◆ last_direct_allocation_

void* msgpack_light::monotonic_allocator::last_direct_allocation_ {nullptr}
private

Last pointer to the memory allocated directly using malloc function.

Definition at line 259 of file monotonic_allocator.h.

◆ max_allocation_from_buffer

std::size_t msgpack_light::monotonic_allocator::max_allocation_from_buffer = 512U
staticconstexpr

Maximum size of memory allocated from buffer.

Definition at line 41 of file monotonic_allocator.h.

◆ next_allocation_point_

void* msgpack_light::monotonic_allocator::next_allocation_point_ {nullptr}
private

Pointer to the byte from which the next allocation starts.

Definition at line 253 of file monotonic_allocator.h.

◆ remaining_buffer_

std::size_t msgpack_light::monotonic_allocator::remaining_buffer_ {initial_buffer_size}
private

Remaining size of the current buffer.

Definition at line 256 of file monotonic_allocator.h.


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