Arrays passed by almost reference?

Yigal Chripun yigal100 at gmail.com
Fri Nov 6 00:52:36 PST 2009


On 06/11/2009 07:07, Bob Jones wrote:
> "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.
>
>

I agree with the above.

the semantics should be:
DynamicArray!(T) as a dynamic array
int[x] is a static array
RandomAccessRange!(T) is a slice

int[] a; // compile error

(names are not important ATM)

I don't think there's a need for a dedicated array slice type and 
instead they should be range types.
It should be easy to change underlining containers with compatible range 
types.




More information about the Digitalmars-d mailing list