Bug 18259 – allocatorObject's CAllocatorImpl should store the passed allocator within
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-01-17T22:03:38Z
Last change time
2018-01-17T22:55:56Z
Assigned to
Eduard Staniloiu
Creator
Eduard Staniloiu
Comments
Comment #0 by edi33416 — 2018-01-17T22:03:38Z
allocatorObject uses the passed allocator to allocate the memory chunk that will store the CAllocatorImpl instance, and thus, the allocator stored within the newly created instance should be the one that was passed to the function.
This being said, the unittest below should pass.
unittest
{
import std.conv;
import std.experimental.allocator.mallocator;
import std.experimental.allocator.building_blocks.stats_collector;
alias SCAlloc = StatsCollector!(Mallocator, Options.bytesUsed);
SCAlloc statsCollectorAlloc;
assert(statsCollectorAlloc.bytesUsed == 0);
auto _allocator = allocatorObject(statsCollectorAlloc);
// Ensure that the allocator was passed through in CAllocatorImpl
// This allocator was used to allocate the chunk that holds the
// CAllocatorImpl object; which is it's own wrapper
assert(_allocator.impl.bytesUsed == stateSize!(CAllocatorImpl!(SCAlloc)));
_allocator.allocate(1);
assert(_allocator.impl.bytesUsed == stateSize!(CAllocatorImpl!(SCAlloc)) + 1);
}