Returning const ref (structs) in D

Stian stian.pedersen at gmail.com
Sat Nov 24 14:01:31 PST 2012


After reading that a couple of times it is a bit clearer, thank 
you. I need to wrap my head around this. I am working on a simple 
render/game engine, where, of course, vectors and matrices are 
flying around.

Is the compiler sophisticated enough that is it able to avoid the 
copying. For instance, if i have a struct Matrix4x4 a = 
node.getTransformation() and use a for whatever, but never alter 
it, will it be able to avoid the copy? What if i declare it const 
or immutable? Do i have to use a pointer to it?

After doing some small stuff in D I am not impressed by the 
mental mapping I am having with the memory system currently. I 
have some more experience with high performance programs in C++ 
and appreciate the transparency of the memory management.


More information about the Digitalmars-d-learn mailing list