std.experimental.allocator.building_blocks.ascending_page_allocator

Types 2

AscendingPageAllocator is a fast and safe allocator that rounds all allocations to multiples of the system's page size. It reserves a range of virtual addresses (using mmap on Posix and VirtualAlloc on Windows) and allocates memory at consecutive virtual addresses.

When a chunk of memory is requested, the allocator finds a range of virtual pages that satisfy the requested size, changing their protection to read/write using OS primitives (mprotect and VirtualProtect, respectively). The physical memory is allocated on demand, when the pages are accessed.

Deallocation removes any read/write permissions from the target pages and notifies the OS to reclaim the physical memory, while keeping the virtual memory.

Because the allocator does not reuse memory, any dangling references to deallocated memory will always result in deterministically crashing the process.

See Also

Fields
size_t pageSize
size_t numPages
void * data
void * offset
size_t pagesUsed
void * readWriteLimit
1000 extraAllocPages
uint alignment
Methods
void[] allocate(size_t n) nothrow @nogcRounds the allocation size to the next multiple of the page size. The allocation only reserves a range of virtual pages but the actual physical memory is allocated on demand, when accessing the mem...
void[] alignedAllocate(size_t n, uint a) nothrow @nogcRounds the allocation size to the next multiple of the page size. The allocation only reserves a range of virtual pages but the actual physical memory is allocated on demand, when accessing the mem...
bool expand(ref void[] b, size_t delta) nothrow @nogcIf the passed buffer is not the last allocation, then `delta` can be at most the number of bytes left on the last page. Otherwise, we can expand the last allocation until the end of the virtual add...
Ternary empty() nothrow @nogcReturns `Ternary.yes` if the allocator does not contain any alive objects and `Ternary.no` otherwise.
Destructors
~thisUnmaps the whole virtual address range on destruction.

SharedAscendingPageAllocator is the threadsafe version of AscendingPageAllocator.

Fields
size_t pageSize
size_t numPages
void * data
void * offset
void * readWriteLimit
1000 extraAllocPages
uint alignment
Methods
void[] allocate(size_t n) nothrow @nogcRounds the allocation size to the next multiple of the page size. The allocation only reserves a range of virtual pages but the actual physical memory is allocated on demand, when accessing the mem...
void[] alignedAllocate(size_t n, uint a) nothrow @nogcRounds the allocation size to the next multiple of the page size. The allocation only reserves a range of virtual pages but the actual physical memory is allocated on demand, when accessing the mem...
private void[] allocateImpl(size_t n, uint a) nothrow @nogc
bool expand(ref void[] b, size_t delta) nothrow @nogcIf the passed buffer is not the last allocation, then `delta` can be at most the number of bytes left on the last page. Otherwise, we can expand the last allocation until the end of the virtual add...