Skip to content

Commit

Permalink
Issue 16984 - Make stdx.allocator.building_blocks.quantizer runnable
Browse files Browse the repository at this point in the history
  • Loading branch information
wilzbach committed Oct 5, 2017
1 parent 3cc6300 commit ff6c0f1
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions std/experimental/allocator/building_blocks/quantizer.d
Expand Up @@ -212,14 +212,19 @@ struct Quantizer(ParentAllocator, alias roundingFunction)
@system unittest
{
import std.experimental.allocator.building_blocks.free_tree : FreeTree;
import std.experimental.allocator.common : roundUpToMultipleOf;
import std.experimental.allocator.gc_allocator : GCAllocator;

size_t roundUpToMultipleOf(size_t s, uint base)
{
auto rem = s % base;
return rem ? s + base - rem : s;
}

// Quantize small allocations to a multiple of cache line, large ones to a
// multiple of page size
alias MyAlloc = Quantizer!(
FreeTree!GCAllocator,
n => n.roundUpToMultipleOf(n <= 16_384 ? 64 : 4096));
n => roundUpToMultipleOf(n, n <= 16_384 ? 64 : 4096));
MyAlloc alloc;
const buf = alloc.allocate(256);
assert(buf.ptr);
Expand Down

0 comments on commit ff6c0f1

Please sign in to comment.