Bug 18779 – StatsCollector empty doesn't take into account the parent allocator

Status
NEW
Severity
trivial
Priority
P4
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2018-04-19T12:31:14Z
Last change time
2024-12-01T16:33:32Z
Assigned to
No Owner
Creator
Eduard Staniloiu
Moved to GitHub: phobos#10330 →

Comments

Comment #0 by edi33416 — 2018-04-19T12:31:14Z
Currently, std.experimental.allocator.building_blocks.StatsCollector does not forward to the parent allocator, but instead, makes an assumption based on the `bytesUsed` option. `empty` is not the StatsCollector's decision to make, since the parent allocator might have a different logic based on empty, than just matching allocations with deallocations. Please see the example below; adding the unittest in stats_collector.d will trigger the assert ``` @system unittest { import std.experimental.allocator.mallocator : Mallocator; import std.typecons : Ternary; static struct MyAlloc { pure nothrow @safe @nogc Ternary empty() { return Ternary.no; } enum uint alignment = platformAlignment; void[] allocate(size_t n) { return Mallocator.instance.allocate(n); } bool deallocate(void[] b) { return Mallocator.instance.deallocate(b); } static MyAlloc instance; } StatsCollector!(MyAlloc, Options.all) a; auto buf = a.allocate(42); a.deallocate(buf); assert(a.empty == Ternary.no); // fails } ```
Comment #1 by robert.schadek — 2024-12-01T16:33:32Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/10330 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB