why allocators are not discussed here

Dmitry Olshansky dmitry.olsh at gmail.com
Wed Jun 26 07:19:54 PDT 2013


26-Jun-2013 14:03, Robert Schadek пишет:
> On 06/26/2013 12:50 AM, Adam D. Ruppe wrote:
>> On Tuesday, 25 June 2013 at 22:22:09 UTC, cybervadim wrote:
>>> (introducing a new keyword allocator)
>>
>> It would be easier to just pass an allocator object that provides the
>> necessary methods and don't use new at all. (I kinda wish new wasn't
>> in the language. It'd make this a little more consistent.)
>>
>
> I did think about this as well, but than I came up with something that
> IMHO is even simpler.
>
> Imagine we have two delegates:
>
> void* delegate(size_t);  // this one allocs
> void delegate(void*);    // this one frees
>
> you pass both to a function that constructs you object. The first is
> used for allocation the
> memory, the second gets attached to the TypeInfo and is used by the gc
> to free
> the object.

Then it's just GC but with an extra complication.

> This would be completely transparent to the user.
>
> The use in a container is similar. Just use the alloc delegate to
> construct the objects and
> attach the free delegate to the typeinfo. You could even mix allocator
> strategies in the middle
> of the lifetime of the container.
>


-- 
Dmitry Olshansky


More information about the Digitalmars-d mailing list