stdx.allocator.mallocator

  • Declaration

    struct Mallocator;

    The C heap allocator.

    Examples

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

    • Declaration

      enum uint alignment;

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

    • Declaration

      shared nothrow @nogc @trusted void[] allocate(size_t bytes);
      shared nothrow @nogc @system bool deallocate(void[] b);
      shared nothrow @nogc @system bool reallocate(ref void[] b, size_t s);

      Standard allocator methods per the semantics defined above. The and methods are because they may move memory around, leaving dangling pointers in user code. Somewhat paradoxically, is but that's only useful to safe programs that can afford to leak memory allocated.

    • Declaration

      static shared 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 .

  • Declaration

    struct AlignedMallocator;

    Aligned allocator using OS-specific primitives, under a uniform API.

    Examples

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

    • Declaration

      enum uint alignment;

      The default alignment is .

    • Declaration

      shared nothrow @nogc @trusted void[] allocate(size_t bytes);

      Forwards to .

    • Declaration

      shared nothrow @nogc @trusted void[] alignedAllocate(size_t bytes, uint a);

      Uses on Posix and on Windows.

    • Declaration

      shared nothrow @nogc @system bool deallocate(void[] b);

      Calls on Posix and on Windows.

    • Declaration

      shared nothrow @nogc @system bool reallocate(ref void[] b, size_t newSize);

      On Posix, forwards to . On Windows, forwards to .

    • Declaration

      static shared AlignedMallocator instance;

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