density
C++11 library for paged memory management, function queues, heterogeneous queues and lifo memory management
|
#include <default_allocator.h>
Public Member Functions | |
void * | allocate (size_t i_size, size_t i_alignment, size_t i_alignment_offset=0) |
void * | try_allocate (size_t i_size, size_t i_alignment, size_t i_alignment_offset=0) noexcept |
void | deallocate (void *i_block, size_t i_size, size_t i_alignment, size_t i_alignment_offset=0) noexcept |
void * | allocate_page () |
void * | try_allocate_page (progress_guarantee i_progress_guarantee) noexcept |
void * | allocate_page_zeroed () |
void * | try_allocate_page_zeroed (progress_guarantee i_progress_guarantee) noexcept |
void | deallocate_page (void *i_page) noexcept |
void | deallocate_page_zeroed (void *i_page) noexcept |
void | pin_page (void *i_page) noexcept |
void | unpin_page (void *i_address) noexcept |
bool | try_pin_page (progress_guarantee i_progress_guarantee, void *i_address) noexcept |
void | unpin_page (progress_guarantee i_progress_guarantee, void *i_address) noexcept |
uintptr_t | get_pin_count (const void *i_address) noexcept |
bool | operator== (const basic_default_allocator &) const noexcept |
bool | operator!= (const basic_default_allocator &) const noexcept |
Static Public Member Functions | |
static void | reserve_lockfree_page_memory (size_t i_size, size_t *o_reserved_size=nullptr) |
static bool | try_reserve_lockfree_page_memory (progress_guarantee i_progress_guarantee, size_t i_size, size_t *o_reserved_size=nullptr) noexcept |
Static Public Attributes | |
static constexpr size_t | page_size = PageAllocator::page_size |
static constexpr size_t | page_alignment = PageAllocator::page_alignment |
Class template providing paged and legacy memory allocation. It meets the requirements of UntypedAllocator and PagedAllocator.
basic_default_allocator is stateless, so instances are interchangeable: blocks and pages can be deallocated by any instance of basic_default_allocator.
|
inline |
Allocates a legacy memory block with the specified size and alignment.
i_size | size of the requested memory block, in bytes |
i_alignment | alignment of the requested memory block, in bytes |
i_alignment_offset | offset of the block to be aligned, in bytes. The alignment is guaranteed only i_alignment_offset bytes from the beginning of the block. |
Progress guarantee: the same of the built-in operator new, usually blocking
Throws: std::bad_alloc on failure
The content of the newly allocated block is undefined.
|
inlinenoexcept |
Tries to allocates a legacy memory block with the specified size and alignment.
i_size | size of the requested memory block, in bytes |
i_alignment | alignment of the requested memory block, in bytes |
i_alignment_offset | offset of the block to be aligned, in bytes. The alignment is guaranteed only i_alignment_offset bytes from the beginning of the block. |
Progress guarantee: the same of the built-in operator new, usually blocking
Throws: nothing
The content of the newly allocated block is undefined.
|
inlinenoexcept |
Deallocates a legacy memory block. After the call any access to the memory block results in undefined behavior.
i_block | block to deallocate, or nullptr. |
i_size | size of the block to deallocate, in bytes. |
i_alignment | alignment of the memory block. |
i_alignment_offset | offset of the alignment |
Progress guarantee: the same of the built-in operator delete, usually blocking
Throws: nothing
If i_block is nullptr, the call has no effect.
|
inline |
Allocates a memory page.
Progress guarantee: blocking
Throws: std::bad_alloc on failure.
The content of the newly allocated page is undefined.
|
inlinenoexcept |
Tries to allocates a memory page.
Progress guarantee: specified by the argument
Throws: nothing
The content of the newly allocated page is undefined.
|
inline |
Allocates a memory page.
Progress guarantee: blocking
Throws: std::bad_alloc on failure.
The content of the newly allocated page is zeroed.
|
inlinenoexcept |
Tries to allocates a memory page.
Progress guarantee: specified by the argument
Throws: nothing
The content of the newly allocated page is zeroed.
|
inlinenoexcept |
Deallocates a memory page. If the page is still pinned by some threads, it is not altered or recycled by the allocator until it is unpinned.
i_page | pointer to a byte within the page to deallocate. Can't be nullptr. |
Progress guarantee: wait free
Throws: nothing
|
inlinenoexcept |
Deallocates a memory page. If the page is still pinned by some threads, it is not altered or recycled by the allocator until it is unpinned. If the page is not pinned, it must be zeroed. Otherwise it must be zeroed when the last pin is removed.
i_page | pointer to a byte within the page to deallocate. Can't be nullptr. |
Progress guarantee: wait free
Throws: nothing
|
inlinestatic |
Reserves the specified memory size from the system for lock-free page allocation.
i_size | the space (in bytes) that the internal page allocator should reserve for page allocation. |
o_reserved_size | pointer to a size_t that receives the actual space (in bytes) that the allocator has allocated from the system, always greater or equal to i_size. This parameter can be null, in which case the actual reserved size is not returned. |
The internal page allocator requests memory regions from the system and uses them to allocate pages with a lock-free algorithm. Regions are returned to the system only during the destruction of global objects.
This function ensures that the sum of the capacity available in the all the regions is at least the specified size. If a new region is necessary in order to reach the specified capacity, but the allocation from the system fails, this function throw a std::bad_alloc.
Note: some of this space may be already allocated as pages.
Progress guarantee: blocking
Throws: std::bad_alloc on failure.
|
inlinestaticnoexcept |
Tries to reserve the specified memory size from the system for lock-free page allocation.
i_progress_guarantee | minimum progress guarantee of this call. If it is not progress_blocking, no region is allocated |
i_size | the space (in bytes) that the internal page allocator should reserve for page allocation. |
o_reserved_size | pointer to a size_t that receives the actual space (in bytes) that the allocator has allocated from the system, always greater or equal to i_size. This parameter can be null, in which case the actual reserved size is not returned |
The internal page allocator requests memory regions from the system and uses them to allocate pages. Regions are returned to the system only during the destruction of global objects.
This function verifies that the sum of memory available in the regions is at least the specified size. Note: some of this space may be already allocated as pages.
Progress guarantee: specified by the argument
Throws: nothing.
|
inlinenoexcept |
Pins the page containing the specified address, incrementing an internal page_specific ref-count.
i_page | pointer to a byte within the page to deallocate. Can't be nullptr. |
If the page has been already deallocated no undefined behavior occurs: the caller should detect this case and unpin the page immediately. Using a deallocated-then-pinned page in any other way other than unpinning (including accessing its content) causes undefined behavior.
If the page is still allocated then the pin ensures that, while the page is pinned:
Every call to pin_page should be matched by a call to unpin_page by the same thread. A thread may pin the same page multiple times, provided that it unpins the page the same number of times.
Progress guarantee: lock-free
Throws: nothing.
|
inlinenoexcept |
Removes a pin from the page, decrementing the internal ref-count.
Progress guarantee: lock-free
Throws: nothing.
|
inlinenoexcept |
Tries to pin the page containing the specified address, incrementing an internal page_specific ref-count, If the implementation can't complete the action with the specified progress guarantee, the call has no visible effects, and the return value is false. Otherwise the return value is true.
Progress guarantee: specified by the argument
Throws: nothing.
|
inlinenoexcept |
Removes a pin from the page, decrementing the internal ref-count.
Progress guarantee: specified by the argument
Throws: nothing.
|
inlinenoexcept |
Returns the number of times the specified page has been pinned by any thread. This function is useful only for diagnostic or debugging.
Progress guarantee: wait-free
Throws: nothing.
|
inlinenoexcept |
Returns whether the right-side allocator can be used to deallocate block and pages allocated by this allocator.
|
inlinenoexcept |
Returns whether the right-side allocator cannot be used to deallocate block and pages allocated by this allocator.
|
static |
Usable size (in bytes) of memory pages.
|
static |
Alignment (in bytes) of memory pages.