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

Dmitry Olshansky dmitry.olsh at gmail.com
Thu Nov 22 13:37:14 PST 2012


11/23/2012 1:02 AM, Walter Bright пишет:

>
> 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.

Expending on it and adding more serious reasoning.

Array ops supposed to be overhead-free loops transparently leveraging 
SIMD parallelism of modern CPUs. No more and no less. It's like 
auto-vectorization but it's guaranteed and obvious in the form.

Now if array ops did the checking for matching lengths it would slow 
them down. And that's something you can't turn off when you know the 
lengths match as it's a built-in. Ditto for checking if the left side is 
already allocated and allocating if not (but it's even worse).

Basically you can't make the fastest primitive on something wrapped in 
safeguards. Doing the other way around is easy, for example via defining 
special wrapper type with custom opSlice, opSliceAssign etc..
that will do the checks.


-- 
Dmitry Olshansky


More information about the Digitalmars-d mailing list