density
C++11 library for paged memory management, function queues, heterogeneous queues and lifo memory management
|
UntypedAllocator encapsulates an untyped memory allocation service, similar to Allocator, defined by the standard, but untyped like std::malloc. UntypedAllocator supports over-alignment and alignment offset. UntypedAllocator is also similar to the class std::pmr::memory_resource (introduced in C++17), but is not polymorphic.
Requirement | Semantic |
---|---|
Non-static member function: void * allocate( size_t i_size, size_t i_alignment, size_t i_alignment_offset = 0); | Allocates a memory block large at least i_size bytes. The address at the offset i_alignment_offset from the beginning of the block is aligned at least to i_alignment. On failure this function should throw a std::bad_alloc. The user is responsible to ensure that:
otherwise the behavior may be undefined. |
Non-static member function: void deallocate( void * i_block, size_t i_size, size_t i_alignment, size_t i_alignment_offset = 0) noexcept; | Deallocates a memory block.
otherwise the behavior may be undefined. |
Operators == and != | Checks for equality\inequality. |
Default constructor and non-throwing destructor | A default constructed allocator is usable to allocate and deallocate memory block. 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 block 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 block. As a consequence, after an allocator A is used as source for a move construction or assignment to an allocator B, any block allocated by A must be deallocated by B. |
basic_default_allocator satisfies the requirements of UntypedAllocator.