Small Vectors Proposal
Oskar Linde
oskar.lindeREM at OVEgmail.com
Thu Feb 1 07:28:21 PST 2007
Andrei Alexandrescu (See Website For Email) wrote:
> Walter Bright wrote:
>> Andrei Alexandrescu (See Website For Email) wrote:
>>> Walter Bright wrote:
>>>> Thank you, this is in line with what I thought you meant. I'm glad I
>>>> was right. Your proposal is sensible and well thought out.
>>>>
>>>> The only improvement I'd make is instead of:
>>>>
>>>> float4 f;
>>>>
>>>> Have:
>>>>
>>>> float[4] f;
>>>>
>>>> i.e. make static arrays of 2,3,4 dimensions have the suggested
>>>> properties. I think this is quite doable.
>>>
>>> I don't think this is advisable. It practically introduces an
>>> arbitrary discontinuity. Think of a template of T and N that
>>> manipulates arrays T[N]. All of a sudden, for certain values of T and
>>> N, arrays started being passed around by value.
>>
>> I agree that it's a very bad idea to have such a discontinuity in ref
>> vs value. Static arrays would have to be all by value or all by ref.
>> Then, you'll just see slower speed for the larger ones.
>
> So then arrays by ref and a stdlib template that wraps an array in a
> struct could make everyone happy.
I disagree. What you describe is a way of working around a design issue
instead of resolving it.
The C (and D) static array has always been an odd type. It is not
assignable, but is passed by reference to functions. You can not return
static arrays from functions. Template libraries like std.bind have to
add lots of extra code to special case the static arrays. Structs
containing static arrays behave differently than static arrays
themselves. Also, in D, the static array is the only type where
typeof(T.init) != T.
If static arrays became a value type, all irregularities could disappear.
The only place this change would make any difference for old code is
where static arrays are passed as function parameters. I believe the
amount of code containing functions with static array arguments is very
small in D. In fact, only two Phobos modules contain such functions
(std.utf and std.md5). Converting those functions would be trivial: The
by ref behavior would be attainable with the inout and out parameter
types that today are forbidden for static arrays.
/Oskar
More information about the Digitalmars-d
mailing list