Returning const ref (structs) in D
Rob T
rob at ucora.com
Sat Nov 24 16:50:16 PST 2012
On Saturday, 24 November 2012 at 22:01:32 UTC, Stian wrote:
> 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?
You may want to read through this thread to help understand how
the move/copy semantics work, this part can be difficult to
understand and appreciate
http://forum.dlang.org/thread/cwywtkycjljdnclqtpqr@forum.dlang.org
> 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.
Yup, I understand that feeling fully.
If you are like me, then you will be expecting D to be similar to
C++ in more ways than it is, and encounters with the differences
will be frustrating at first.
The GC is something else to get used to, and I may never get used
to it after years of mentally mapping out where and how memory is
allocated and deallocated. I just don't trust that a GC will do
the job properly and I have this horrible feeling that it will
waste vast amounts of memory like java apps seem to do, and that
it will miss deallocations for certain edge cases, like a union
with a pointer or class reference in it. At this point, all I
have is faith that it is doing the job properly, but that's not
how I operate. I need to know exactly what it is doing and how to
detect when it is not doing what I think it should be doing. This
is an area I have not tackled yet but intend to.
--rt
More information about the Digitalmars-d-learn
mailing list