Mallocator

The C heap allocator.

Members

Functions

allocate
void[] allocate(size_t bytes)

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.

allocateZeroed
void[] allocateZeroed(size_t bytes)
Undocumented in source. Be warned that the author may not have intended to support it.
deallocate
bool deallocate(void[] b)
reallocate
bool reallocate(void[] b, size_t s)

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.

Static variables

instance
Mallocator instance;

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.

Variables

alignment
enum uint alignment;

The alignment is a static constant equal to platformAlignment, which ensures proper alignment for any D data type.

Examples

auto buffer = Mallocator.instance.allocate(1024 * 1024 * 4);
scope(exit) Mallocator.instance.deallocate(buffer);
//...

Meta