Array append performance

Steven Schveighoffer schveiguy at yahoo.com
Sat Aug 23 13:43:57 PDT 2008


"Bill Baxter" wrote
> On Sun, Aug 24, 2008 at 2:16 AM, Steven Schveighoffer
> <schveiguy at yahoo.com> wrote:
>> "dsimcha" wrote
>
>> I see nothing wrong with having a library solution to this.  D and
>> especially D2 is to the point where syntax of custom structs is really 
>> easy
>> to use.
>>
>> The problem is that many times I don't append to an array or slice, why
>> should I have to accept the cost of an extra 4-8 byte field for every 
>> slice
>> and array that isn't going to change size (which I would argue is used 
>> more
>> often)?
>
> Personally I'd argue that appending efficiently is important to more
> programs than than saving 4-8 bytes here and there.  So that would
> suggest that lean-and-mean fixed-sized arrays should be the library
> solution, and arrays with a capacity field should be the built-in
> type.

Making all arrays (even ones that you create temporarily and never append 
to) have extra data to copy will add up performance-wise.  I think there are 
only a few spots in any of my code that I use the append operator.  So 
'important' it is, but common, I would argue it is not.  Of course, I only 
present anectodal evidence :)

There's also the advantage of backwards compatibility, and not having to 
change the D spec.

-Steve 





More information about the Digitalmars-d mailing list