Bug 23090 – Allocators should not use NullAllocator as a sentinel type

Status
NEW
Severity
enhancement
Priority
P4
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-05-04T17:43:49Z
Last change time
2024-12-01T16:40:02Z
Assigned to
No Owner
Creator
Paul Backus
Moved to GitHub: phobos#10492 →

Comments

Comment #0 by snarwin+bugzilla — 2022-05-04T17:43:49Z
Several allocators in std.experimental.allocator have special-case behavior when instantiated using the specific type `NullAllocator`. A non-exhaustive list: * Region: "If ParentAllocator is different from NullAllocator, Region deallocates the chunk of memory during destruction." [1] * ContiguousFreeList: "The block is assumed to have been allocated with ParentAllocator, and is released in ContiguousFreeList's destructor (unless ParentAllocator is NullAllocator)." [2] * AllocatorList: "If BookkeepingAllocator is NullAllocator, then AllocatorList is "ouroboros-style", i.e. it keeps the bookkeeping data in memory obtained from the allocators themselves." [3] It is clear from these examples that the type `NullAllocator` is being used as a sentinel to indicate the *absence* of an allocator, rather than for its actual documented purpose of being an allocator that is always out of memory. This abuse of NullAllocator has two undesirable consequences: 1. Users who want NullAllocator's out-of-memory behavior must define their own version with a different name, rather than using NullAllocator directly. 2. Readers of the std.experimental.allocator documentation are likely to come away confused about NullAllocator's purpose. [1] https://dlang.org/library/std/experimental/allocator/building_blocks/free_list/contiguous_free_list.html [2] https://dlang.org/library/std/experimental/allocator/building_blocks/free_list/contiguous_free_list.html [3] https://dlang.org/library/std/experimental/allocator/building_blocks/allocator_list/allocator_list.html
Comment #1 by dlang-bot — 2022-09-19T19:23:53Z
@pbackus updated dlang/phobos pull request #8574 "[allocator/region] Issue 23090 - Don't use NullAllocator as a sentinel type" mentioning this issue: - Region: don't use NullAllocator as a sentinel Region will now always assume that its ParentAllocator is a real allocator, and attempt to use its 'allocate' and 'deallocate' methods accordingly. The behavior previously provided by Region!(NullAllocator, ...) remains available via BorrowedRegion!(...). See issue 23090 for detailed rationale. - SharedRegion: don't use NullAllocator as sentinel SharedRegion will now always assume that its ParentAllocator is a real allocator, and attempt to use its 'allocate' and 'deallocate' methods accordingly. The behavior previously provided by SharedRegion!(NullAllocator, ...) remains available via shared(BorrowedRegion!(...)). See issue 23090 for detailed rationale. https://github.com/dlang/phobos/pull/8574
Comment #2 by robert.schadek — 2024-12-01T16:40:02Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/10492 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB