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 and is copyable, the result will store a copy of it within. The result itself is allocated in its own statically-typed allocator.
  • If A has state and is not copyable, the result will move the passed-in argument into the result. The result itself is allocated in its own statically-typed allocator.
  1. CAllocatorImpl!A allocatorObject(auto ref A a)
  2. CAllocatorImpl!(A, Yes.indirect) allocatorObject(A* pa)
    CAllocatorImpl!(A, Yes.indirect)
    allocatorObject
    (
    A
    )
    (
    A* pa
    )

Examples

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

Meta