density
C++11 library for paged memory management, function queues, heterogeneous queues and lifo memory management
|
The PagedAllocator concept encapsulates a page-based untyped memory allocation service. All pages allocated by a PagedAllocator have the same fixed size and alignment requirements.
Requirement | Semantic |
---|---|
Static constexpr member variable: static constexpr size_t page_size; | Specifies the size of a page in bytes, that is always less than or equal to the alignment. |
Static constexpr member variable: static constexpr size_t page_alignment; | Specifies the minimum alignment of a page in bytes, that is always greater than zero and an integer power of 2. |
Non-static member function: void * allocate_page(); | Allocates a memory page large at least page_size bytes. The first byte of the page is aligned at least to page_alignment. On failure this function should throw a std::bad_alloc. |
Non-static noexcept member function: void * try_allocate_page(progress_guarantee i_progress_guarantee); | Tries to allocate a memory page large at least page_size bytes with the specified progression guarantee. The first byte of the page is aligned at least to page_alignment. The return value is a pointer to the first byte of the memory page. The content of the page is undefined. Returns null on failure. |
Non-static member function: void * allocate_page_zeroed(); | Allocates a memory page large at least page_size bytes. The first byte of the page is aligned at least to page_alignment. On failure this function should throw a std::bad_alloc. |
Non-static noexcept member function: void * try_allocate_page_zeroed(progress_guarantee i_progress_guarantee); | Tries to allocate a memory page large at least page_size bytes with the specified progression guarantee. The first byte of the page is aligned at least to page_alignment. The return value is a pointer to the first byte of the memory page. The content of the page is zeroed. Returns null on failure. |
Non-static noexcept member function: void deallocate_page(void * i_page); | Deallocates the memory page containing the provided address. This function must be wait-free. |
Non-static noexcept member function: void deallocate_page_zeroed(void * i_page); | Deallocates the memory page containing the provided address, assuming that as soon it is not pinned its content is zeroed. This function must be wait-free. |
Non-static noexcept member function: void pin_page(void * i_page); | Pins the memory page containing the provided address, preventing it from being altered or recycled. The page be already deallocated, in which case the caller will unpin it immediately. This function must be lock-free. |
Non-static noexcept member function: void unpin_page(void * i_page); | Unpins the memory page containing the provided address, that must have previously been pinned, stopping the effect of the pin. This function must be lock-free. |
Operators == and != | Checks for equality\inequality. |
Default constructor and non-throwing destructor | A default constructed allocator is usable to allocate and deallocate memory pages. The destructor must be no-except. |
Copy constructor and copy assignment | A copy-constructed allocator compares equal to the source of the copy. As a consequence, a pages allocated by an allocator can be deallocated by an allocator that was copy-constructed from it. Same for assignment. |
Non-throwing move constructor and non-throwing move assignment | A move-constructed allocator may not compare equal to the source of the move. After a move construction or assignment, the source of the move cannot be used to allocate or deallocate any page. As a consequence, after an allocator A is used as source for a move construction or assignment to an allocator B, any page allocated by A must be deallocated by B. |
basic_default_allocator satisfies the requirements of PagedAllocator.