Array Operations: a[] + b[] etc.

Walter Bright newshound2 at digitalmars.com
Thu Nov 22 13:02:53 PST 2012


On 11/22/2012 3:25 AM, John Colvin wrote:
> c[] = a[] + b[];
> fast, in place array operation, the cost of allocation happens earlier in the code.
>
> but also
> c = a[] + b[];
> a much slower, memory assigning array operation, pretty much just shorthand for
> c = new T[a.length];
> c[] = a[] + b[];
>
> You could argue that hiding an allocation is bad, but I would think it's quite
> obvious to any programmer that if you add 2 arrays together, you're going to
> have to create somewhere to put them... Having the shorthand prevents any
> possible mistakes with the length of the new array and saves a line of code.

I'll be bold and predict what will happen if this proposal is implemented:

     "Array operations in D are cool but are incredibly slow. D sux."

Few will notice that the hidden memory allocation can be easily removed, 
certainly not people casually looking at D to see if they should use it, and the 
damage will be done.


More information about the Digitalmars-d mailing list