Debian Codegraph @

libphobos/testsuite/libphobos.phobos/std_experimental_allocator_building_blocks_kernighan_ritchie.d

raw
1 @system unittest
2 {
3 import std.experimental.allocator.building_blocks.kernighan_ritchie;
4
5 import std.experimental.allocator.gc_allocator : GCAllocator;
6 auto alloc = KRRegion!GCAllocator(1024 * 64);
7 const b1 = alloc.allocate(2048);
8 assert(b1.length == 2048);
9 const b2 = alloc.allocateAll;
10 assert(b2.length == 1024 * 62);
11
12 }
13
14 @system unittest
15 {
16 import std.experimental.allocator.building_blocks.kernighan_ritchie;
17
18 import std.experimental.allocator.building_blocks.fallback_allocator
19 : fallbackAllocator;
20 import std.experimental.allocator.gc_allocator : GCAllocator;
21 import std.typecons : Ternary;
22 // KRRegion fronting a general-purpose allocator
23 align(KRRegion!().alignment) ubyte[1024 * 128] buf;
24 auto alloc = fallbackAllocator(KRRegion!()(buf), GCAllocator.instance);
25 auto b = alloc.allocate(100);
26 assert(b.length == 100);
27 assert((() pure nothrow @safe @nogc => alloc.primary.owns(b))() == Ternary.yes);
28 }
29
30 @system unittest
31 {
32 import std.experimental.allocator.building_blocks.kernighan_ritchie;
33
34 import std.algorithm.comparison : max;
35 import std.experimental.allocator.building_blocks.allocator_list
36 : AllocatorList;
37 import std.experimental.allocator.mmap_allocator : MmapAllocator;
38 AllocatorList!(n => KRRegion!MmapAllocator(max(n * 16, 1024 * 1024))) alloc;
39 }
40