Array append performance 2

Fawzi Mohamed fmohamed at mac.com
Sun Aug 31 05:11:07 PDT 2008


On 2008-08-31 06:01:26 +0200, Sean Kelly <sean at invisibleduck.org> said:

> dsimcha wrote:
>> Nice work on the reference template.  I had thought that the typeid(T).flags()
>> would be inlined, then constant folded, but CTFE doesn't work on it, so I guess
>> not.  Probably pretty negligible, but if I have a template laying around to do
>> this at compile time, I may as well use it.
>> 
>> Also, to answer your question, you do need to call hasNoPointers() each 
>> time you
>> realloc.
> 
> Not with Tango.
> 
> 
> Sean

I would have done it quite differently: keep a linked list (if you want 
to improve of batches of 10 arrays), with a pointer to the end, append 
in O(1), and keep the total length.

only upon a call to toArray allocate an array of the requested length 
and fill it.

An array (even with tricks) is not a good structure to append to, so it 
seems a bad idea to me to use it.

Fawzi




More information about the Digitalmars-d mailing list