Arrays passed by almost reference?

Bob Jones me at not.com
Thu Nov 5 21:07:56 PST 2009


"Leandro Lucarella" <llucax at gmail.com> wrote in message 
news:20091106035612.GI3748 at llucax.com.ar...
>>
>> I am not fully against pass-by-ref arrays, I just think in passing by
>> reference all of the time could have some performance implications.
>
> OK, make 2 different types then: slices (value types, can't append, they
> are only a view on other's data) and dynamic arrays (reference type, can
> append, but a little slower to manipulate).
>
> It's a shame this idea didn't came true after all...

Thats the whole problem. Dynamic arrays and slices are not the same thing, 
and having a syntax that allows code to be ignorant of which it is dealing 
with is always going to have problems imo. Being able to resize or append to 
slices is fubar imo.

I'd go with slices being value types, no concentenation, or resizing / 
reallocating, etc..

Dynamic arrays could be a library type. A templated struct that has a 
pointer, length, or whatever. They can have operator overloads for implicit 
convertion to slices, so any code that accepts slice can take dynamic 
arrays, and prevent side effects. Code that is going to reallocate, has to 
take a dynamic array. So at least whats happening is more obvious/explicit.





More information about the Digitalmars-d mailing list