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
size_t pageSizesize_t numPagesvoid * datavoid * offsetsize_t pagesUsedvoid * readWriteLimit1000 extraAllocPagesuint alignmentvoid[] 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...~thisUnmaps the whole virtual address range on destruction.SharedAscendingPageAllocator is the threadsafe version of AscendingPageAllocator.
size_t pageSizesize_t numPagesvoid * datavoid * offsetvoid * readWriteLimit1000 extraAllocPagesSpinLock lockuint alignmentvoid[] 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...