mirror of
https://github.com/dlang/phobos.git
synced 2025-04-29 14:40:30 +03:00
23 lines
855 B
Text
23 lines
855 B
Text
Replace `std.experimental.allocator.ISharedAllocator` with `std.experimental.allocator.RCISharedAllocator`
|
|
|
|
$(B Motivation):
|
|
|
|
Keep track of references to allocators so they don't escape, dangle,
|
|
and cause undefined behavior.
|
|
|
|
From now on, `RCISharedAllocator` will be used instead of the old
|
|
`ISharedAllocator` interface.
|
|
$(REF sharedAllocatorObject, std, experimental, allocator)` can be used to build
|
|
a `RCISharedAllocator` out of a custom allocator.
|
|
|
|
------
|
|
import std.experimental.allocator.building_blocks.free_list : SharedFreeList;
|
|
import std.experimental.allocator.mallocator : Mallocator;
|
|
|
|
shared SharedFreeList!(Mallocator, chooseAtRuntime, chooseAtRuntime) sharedFL;
|
|
shared RCISharedAllocator sharedFLObj = sharedAllocatorObject(sharedFL);
|
|
|
|
auto b = sharedFLObj.allocate(100);
|
|
assert(b.length == 100);
|
|
assert(sharedFLObj.deallocate(b));
|
|
------
|