Vectors and matrices in D

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Thu Mar 15 12:31:11 PDT 2007


Jascha Wetzel wrote:
> Bill Baxter wrote:
>> The main problem is that passing big structs by value as parameters is
>> kind of slow.  And it's something you want a lot.  In C++ you'd use
>> const& Vector for the argument types, but in D there's no equivalent.
> 
> what about inout? it does exactly that.

No, it doesn't do "exactly that". 'inout Vector' is more like 'Vector&' 
(i.e. a mutable reference instead of a non-mutable reference). From a 
performance viewpoint they are equivalent, but not from a semantics 
viewpoint.
A while back Andrei and Walter were talking about adding, among other 
things, the concept of non-mutable references to the language. It's been 
a bit quiet on that front though.

> DMD will even pass single inout arguments in a register.

That it will, unless the function is a member function (or delegate). 
Though in that case the this/context pointer may technically be 
considered an extra parameter.
IIRC GDC for amd64 will put several parameters in registers though, 
since the calling convention seems to be based on the C one which uses 
several registers before spilling over to the stack on that architecture.


More information about the Digitalmars-d-learn mailing list