Skip to content

Commit

Permalink
Merge pull request #4758 from japplegame/patch-2
Browse files Browse the repository at this point in the history
fix AllocatorList.allocate weird behavior
  • Loading branch information
andralex committed Aug 30, 2016
2 parents 6394458 + e56ac36 commit b291600
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion std/experimental/allocator/building_blocks/allocator_list.d
Expand Up @@ -173,8 +173,8 @@ struct AllocatorList(Factory, BookkeepingAllocator = GCAllocator)
*p = n.next;
n.next = root;
root = n;
return result;
}
return result;
}
// Can't allocate from the current pool. Check if we just added a new
// allocator, in that case it won't do any good to add yet another.
Expand Down Expand Up @@ -615,3 +615,24 @@ unittest
a.deallocateAll();
assert(a.empty == Ternary.yes);
}

unittest
{
import std.experimental.allocator.building_blocks.region : Region;
enum bs = GCAllocator.alignment;
AllocatorList!((n) => Region!GCAllocator(256 * bs)) a;
auto b1 = a.allocate(192 * bs);
assert(b1.length == 192 * bs);
assert(a.allocators.length == 1);
auto b2 = a.allocate(64 * bs);
assert(b2.length == 64 * bs);
assert(a.allocators.length == 1);
auto b3 = a.allocate(192 * bs);
assert(b3.length == 192 * bs);
assert(a.allocators.length == 2);
a.deallocate(b1);
b1 = a.allocate(64 * bs);
assert(b1.length == 64 * bs);
assert(a.allocators.length == 2);
a.deallocateAll();
}

0 comments on commit b291600

Please sign in to comment.