AlignedMallocator

Undocumented in source.

Members

Static functions

alignedAllocate
void[] alignedAllocate(size_t bytes, uint a)

Uses posix_memalign on Posix and __aligned_malloc on Windows.

alignedAllocate
void[] alignedAllocate(size_t bytes, uint a)
Undocumented in source. Be warned that the author may not have intended to support it.
alignedReallocate
bool alignedReallocate(void[] b, size_t s, uint a)

On Posix, uses alignedAllocate and copies data around because there is no realloc for aligned memory. On Windows, calls __aligned_realloc(b.ptr, newSize, a).

allocate
void[] allocate(size_t bytes)

Forwards to alignedAllocate(bytes, platformAlignment).

deallocate
bool deallocate(void[] b)

Calls free(b.ptr) on Posix and __aligned_free(b.ptr) on Windows.

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

On Posix, forwards to realloc. On Windows, forwards to alignedReallocate(b, newSize, platformAlignment).

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

Variables

alignment
enum uint alignment;

The default alignment is platformAlignment.

instance
enum AlignedMallocator instance;

Returns the global instance of this allocator type. The C heap allocator is thread-safe, therefore all of its methods are static and instance itself is shared.

Examples

auto buffer = AlignedMallocator.instance.alignedAllocate(1024 * 1024 * 4,
    128);
scope(exit) AlignedMallocator.instance.deallocate(buffer);
//...

Meta