Allocators in Phobos

dsimcha dsimcha at yahoo.com
Mon Aug 22 06:02:02 PDT 2011


On 8/22/2011 7:07 AM, Steven Schveighoffer wrote:
>> newArray: Creates a new array. Can be syntactic sugar for (cast(T*)
>> allocate(T.sizeof * nElements))[0..nElements] or can do something more
>> complicated based on knowing what type T is.
>>
>> uninitializedArray: Same as newArray but doesn't initialize elements.
>
> According to your syntactic sugar description, newArray does not
> initialize elements, is this not the case?
>
> I'm assuming so, otherwise, why the extra function :)

Yes, newArray does initialize elements.  My mistake.

> 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
>
>
> -Steve

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.


More information about the Digitalmars-d mailing list