The C heap allocator.
The C heap allocator.
auto buffer = Mallocator.instance.allocate(1024 * 1024 * 4); scope(exit) Mallocator.instance.deallocate(buffer); //...
The alignment is a static constant equal to platformAlignment
, which ensures proper alignment for any D data type.
Standard allocator methods per the semantics defined above. The deallocate
and reallocate
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.
Returns the global instance of this allocator type. The C heap allocator is thread-safe, therefore all of its methods and it
itself are shared
.
Aligned allocator using OS-specific primitives, under a uniform API.
auto buffer = AlignedMallocator.instance.alignedAllocate(1024 * 1024 * 4, 128); scope(exit) AlignedMallocator.instance.deallocate(buffer); //...
The default alignment is platformAlignment
.
Forwards to alignedAllocate(bytes, platformAlignment)
.
Uses posix_memalign
on Posix and __aligned_malloc
on Windows.
Calls free(b.ptr)
on Posix and __aligned_free(b.ptr)
on Windows.
Forwards to alignedReallocate(b, newSize, platformAlignment)
. Should be used with blocks obtained with allocate
otherwise the custom alignment passed with alignedAllocate
can be lost.
Returns the global instance of this allocator type. The C heap allocator is thread-safe, therefore all of its methods and instance
itself are shared
.
© 1999–2019 The D Language Foundation
Licensed under the Boost License 1.0.
https://dlang.org/phobos/std_experimental_allocator_mallocator.html