Allocators in Phobos

Steven Schveighoffer schveiguy at yahoo.com
Mon Aug 22 06:36:45 PDT 2011


On Mon, 22 Aug 2011 09:21:43 -0400, Steven Schveighoffer  
<schveiguy at yahoo.com> wrote:

> On Mon, 22 Aug 2011 09:02:02 -0400, dsimcha <dsimcha at yahoo.com> wrote:
>
>> On 8/22/2011 7:07 AM, Steven Schveighoffer wrote:
>>> Take a look at dcollections' chunk allocator, which is under boost
>>> license. It implements a free list + efficient allocation/deallocation
>>> by dividing up a large block. It might be a fit for this, or at least a
>>> starting point.
>>>
>>> One difference from this allocator vs. the generic ones you are
>>> implementing is that it's templated on the type being allocated. It's
>>> intended to be used for a collection, which only allocates one type (a
>>> node). Does this kind of thinking belong in phobos? I'm not sure. But I
>>> think we can at least reuse the free list implementation.
>>>
>>> http://www.dsource.org/projects/dcollections/browser/branches/d2/dcollections/DefaultAllocator.d#L41
>>>
>>
>> Hmm, your chunk allocator looks like a generalization of  
>> FreeListAllocator.  If I get around to implementing FreeListAllocator,  
>> I'll add support for allocating chunks instead of one element per heap  
>> allocation.
>
> Well, I think the GC already uses free lists...  What would be the point  
> of one on top of that, especially if the "block size" is constant?
>
> https://github.com/D-Programming-Language/druntime/blob/master/src/gc/gcx.d#L505
> https://github.com/D-Programming-Language/druntime/blob/master/src/gc/gcx.d#L927

I didn't fully read your FreeListAllocator proposal, I lost that it was on  
*top of* another allocator.  So obviously, it wouldn't make much sense to  
do it on top of the GC, but it could make sense on top of a different  
allocator (say the C malloc allocator).

In that case, I agree the chunk allocator could be an option for the free  
list allocator.

-Steve


More information about the Digitalmars-d mailing list