Mallocator;auto buffer =Mallocator.instance.allocate(1024 * 1024 * 4);scope(exit)Mallocator.instance.deallocate(buffer);//...
alignment;allocate(size_tbytes) shared const;deallocate(void[]b) shared const;reallocate(ref void[]b, size_ts) shared const;deallocate andreallocate methods are@system because they may move memory around, leaving dangling pointers in user code. Somewhat paradoxically,malloc is@safe but that's only useful to safe programs that can afford to leak memory allocated.instance;AlignedMallocator;auto buffer =AlignedMallocator.instance.alignedAllocate(1024 * 1024 * 4, 128);scope(exit)AlignedMallocator.instance.deallocate(buffer);//...
alignment;allocate(size_tbytes) shared;alignedAllocate(size_tbytes, uinta) shared;deallocate(void[]b) shared;b.ptr) on Posix and__aligned_free(b.ptr) on Windows.reallocate(ref void[]b, size_tnewSize) shared;alignedReallocate(ref void[]b, size_ts, uinta) shared;instance;instance itself areshared.