BigInt -- a challenge for std.allocator

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Wed Oct 30 11:02:02 PDT 2013


On 10/30/13 9:35 AM, Dmitry Olshansky wrote:
> 30-Oct-2013 01:59, Joseph Rushton Wakeling пишет:
>> On 29/10/13 15:58, Dmitry Olshansky wrote:
>>> Can't it use ref-counted COW? Then since there is only 1 reference to
>>> the
>>> original block it may mutate it in-place else it creates new chunk
>>> with refs=1
>>> and decrements the original count. Maybe I'm missing something but it
>>> shouldn't
>>> be that hard.
>>
>> Yes, that's pretty much what I was thinking of.  The question is how to
>> implement it in terms of std.allocator -- or is that the wrong base to
>> build ref=counted memory upon?
>>
>
> Like others said - just use allocator.alloc/allocator.free instead of
> malloc/free nothing stellar.

Well actually there are things that can be done at the allocator level 
to explicitly help reference counting:

1. The refcount could be an affix to the allocated block.

2. Small refcounts can be kept together in a compact block a la HeapBlock.

3. Or refcounts can be kept in a freelist.

So refounting can be helped by an allocator built especially for it.


Andrei



More information about the Digitalmars-d mailing list