View source code
Display the source code in std/experimental/allocator/package.d from which thispage was generated on github.
Report a bug
If you spot a problem with this page, click here to create aBugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.Requires a signed-in GitHub account. This works well for small changes.If you'd like to make larger changes you may want to consider usinglocal clone.
Function std.experimental.allocator.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.
RCIAllocator allocatorObject(A)(
auto ref A a
)
if (!isPointer!A);
RCIAllocator allocatorObject(A)(
A* pa
);
- If
A
has no state, the resulting object is allocated in static shared storage. - If
A
has state, the result willmove
the supplied allocatorA a
within. The result itself is allocated in its own statically-typed allocator.
Example
import std .experimental .allocator .mallocator : Mallocator;
RCIAllocator a = allocatorObject(Mallocator .instance);
auto b = a .allocate(100);
writeln(b .length); // 100
assert(a .deallocate(b));
// The in-situ region must be used by pointer
import std .experimental .allocator .building_blocks .region : InSituRegion;
auto r = InSituRegion!1024();
a = allocatorObject(&r);
b = a .allocate(200);
writeln(b .length); // 200
// In-situ regions can deallocate the last allocation
assert(a .deallocate(b));
Authors
License
Copyright © 1999-2025 by the D Language Foundation | Page generated by ddox.