Bulk allocation and partial deallocation for tree data structures.
Moritz Maxeiner via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Jul 3 18:56:11 PDT 2017
On Monday, 3 July 2017 at 17:06:10 UTC, Ali Çehreli wrote:
> On 07/02/2017 07:56 PM, Stefan Koch wrote:
>> On Monday, 3 July 2017 at 02:51:49 UTC, Filip Bystricky wrote:
>>> Anyone?
>>
>> The answer is no.
>>
>> Partial deallocation in an arbitrary fashion is not advisable.
>>
>> And there are no standard library mechanisms for it.
>
> Would it be possible to write a custom
> std.experimental.allocator that does this?
Since the `deallocate` function an Allocator has to implement
takes a `void[]` (-> known size), it's possible:
At deallocation the Allocator will have to check if the given
memory subblock lies within any of the previously allocated
memory blocks; if it does, it will have to "tear" the
to-be-deallocated memory subblock from within it, storing the
resulting prefix and suffix memory subblocks (both remain
allocated) and removing the original block. It will still have to
track those two subblocks as belonging together, though, since it
can only deallocate the original memory block back to the parent
allocator (another Allocator, or something else) once both of
these subblocks are no longer allocated. Obviously this applies
to further partial deallocations of subblocks within subblocks.
I tend to agree with Stefan that this is likely not sensible, but
if in doubt, benchmark for the specific use case.
More information about the Digitalmars-d-learn
mailing list