density
C++11 library for paged memory management, function queues, heterogeneous queues and lifo memory management
UntypedAllocator (named requirement)

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.

UntypedAllocator Requirements
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 return value is a pointer to the first byte of the memory block. The content of the block is undefined.
If i_alignment_offset is not zero, in general the allocator has no requirements on the alignment of the first byte of the block. Anyway, since the address at i_alignment_offset will have n low-order zero bits (where i_alignment = 1 << n), if i_alignment_offset has m low-order zero bits (that is aligned to 1 << m), then the address of the first byte of the block is aligned at least to 1 << min(n,m).

The user is responsible to ensure that:

  • i_alignment must be greater than zero and an integer power of 2
  • i_alignment_offset must be less than or equal to i_size

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.
The user is responsible to ensure that:

  • i_block is a block allocated by the same allocator, or by an allocator that compares equal to it.
  • i_size, i_alignment and i_alignment_offset are the same used when the block was allocated.

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.