How to destruct class instances allocated by a Region-allocator over a single GC block
Per Nordlöw
per.nordlow at gmail.com
Sat Apr 7 14:57:43 UTC 2018
On Saturday, 7 April 2018 at 07:50:37 UTC, Eduard Staniloiu wrote:
> On Friday, 6 April 2018 at 21:49:37 UTC, Per Nordlöw wrote:
>> On Tuesday, 3 April 2018 at 09:14:28 UTC, Eduard Staniloiu
>> wrote:
>>> So, say `reg` is your allocator, your workflow would be
>>>
>>> auto obj = reg.make!Type(args);
>>> /* do stuff */
>>> reg.dispose(obj); // If Type has a __dtor, it will call
>>> obj.__dtor
>>> // and then reg.deallocate(obj)
>>
>> If I do sucessive calls to reg.make!X where X are different
>> kinds of classes of different sizes how does reg.dispose(obj)
>> figure out at which address(es) (where emplace filled in the
>> data) the objects reside?
>
> It can't figure out. With custom allocators you have to
> manually do
> the memory management, so the responsibility of when and which
> object needs
> to be destroyed falls on the user of the custom allocator.
IMHO, such a complexity should be wrapped in a typed allocation
layer. Have Andrei spoken anything about `TypedAllocator`(s) to
wrap this complexity?
More information about the Digitalmars-d-learn
mailing list