How do you remove/insert elements in a dynamic array without allocating?

Malte Skarupke malteskarupke at web.de
Tue Nov 6 19:45:04 PST 2012


On Tuesday, 6 November 2012 at 09:10:08 UTC, bearophile wrote:
> Malte Skarupke:
>
>> I will most certainly never use dynamic arrays or slices again 
>> for anything that needs to grow or shrink dynamically.
>
> And doing so you will miss an important and handy part of D :-/
>
> Bye,
> bearophile

I implemented my own DynamicArray struct which behaves more like 
I want it to and is still giving me all of the benefits that I 
want from dynamic arrays.

Having no clear ownership for the array is not something I am 
willing to accept. Same thing for the non-deterministic copying 
and destruction behavior for the elements. That's the kind of 
thing which looks convenient at first, but will create many small 
performance problems. Once those add up to a big problem, it's 
incredibly frustrating to fix because your slow downs are from 
all over the place.

I don't anticipate that I will ever run into a situation where I 
want to append to a range without caring about whether it 
allocates and copies or not. If I want to append to a range, I 
will write the extra line to create a copy manually.
Because of that I don't need the syntactic ambiguity of treating 
a range the same as an array.


More information about the Digitalmars-d mailing list