std.container update

Steven Schveighoffer schveiguy at yahoo.com
Fri May 28 07:16:11 PDT 2010


On Fri, 28 May 2010 07:58:55 -0400, Jonathan M Davis  
<jmdavisProg at gmail.com> wrote:

>> BTW, what would be the point of an array/vector when you have built-in
>> arrays? If built-in arrays would be syntax sugar for a real library  
>> type,
>> like AAs, I can see as a good option using Array for that type, since
>> built-in arrays and the library Array would be the same thing.
>
> The biggest difference is that a vector has capacity separate from its
> size/length. You can efficiency insert elements at the end with a vector  
> -
> amortized constant time usually - but you can't do that with a built-in
> array because it would have to reallocate every time. D's arrays are
> fantastic, but they're still not quite good enough to outright replace a
> vector type.
>

This isn't exactly true.  D's builtin arrays also are amortized constant  
time to append, but the constant is way higher :)

I agree that an array-like container would provide features that D's  
builtin arrays do not, including much better append performance.

-Steve


More information about the Digitalmars-d mailing list