allocatorObject

Returns a dynamically-typed CAllocator built around a given statically- typed allocator a of type A. Passing a pointer to the allocator creates a dynamic allocator around the allocator pointed to by the pointer, without attempting to copy or move it. Passing the allocator by value or reference behaves as follows.

  • If A has no state, the resulting object is allocated in static shared storage.
  • If A has state, the result will std.algorithm.mutation.move the supplied allocator A a within. The result itself is allocated in its own statically-typed allocator.
  1. RCIAllocator allocatorObject(A a)
    allocatorObject
    (
    A
    )
    (
    auto ref A a
    )
  2. RCIAllocator allocatorObject(A* pa)

Examples

1 import std.experimental.allocator.mallocator : Mallocator;
2 
3 RCIAllocator a = allocatorObject(Mallocator.instance);
4 auto b = a.allocate(100);
5 assert(b.length == 100);
6 assert(a.deallocate(b));
7 
8 // The in-situ region must be used by pointer
9 import std.experimental.allocator.building_blocks.region : InSituRegion;
10 auto r = InSituRegion!1024();
11 a = allocatorObject(&r);
12 b = a.allocate(200);
13 assert(b.length == 200);
14 // In-situ regions can deallocate the last allocation
15 assert(a.deallocate(b));

Meta

Suggestion Box / Bug Report