| 1 |
@system unittest |
| 2 |
{ |
| 3 |
import std.experimental.allocator.building_blocks.quantizer; |
| 4 |
|
| 5 |
import std.experimental.allocator.building_blocks.free_tree : FreeTree; |
| 6 |
import std.experimental.allocator.gc_allocator : GCAllocator; |
| 7 |
|
| 8 |
size_t roundUpToMultipleOf(size_t s, uint base) |
| 9 |
{ |
| 10 |
auto rem = s % base; |
| 11 |
return rem ? s + base - rem : s; |
| 12 |
} |
| 13 |
|
| 14 |
// Quantize small allocations to a multiple of cache line, large ones to a |
| 15 |
// multiple of page size |
| 16 |
alias MyAlloc = Quantizer!( |
| 17 |
FreeTree!GCAllocator, |
| 18 |
n => roundUpToMultipleOf(n, n <= 16_384 ? 64 : 4096)); |
| 19 |
MyAlloc alloc; |
| 20 |
const buf = alloc.allocate(256); |
| 21 |
assert(buf.ptr); |
| 22 |
} |
| 23 |
|