On Wednesday, 13 February 2013 at 23:22:03 UTC, Ivan Kazmenko wrote:
Hi!
-----
Ivan Kazmenko.

Keep in mind that C++ and D have very different philosophies regarding copy construction.

C++ has "strong ownership", so for example, whenever you copy a string/vector, or pass it by value, the whole damn thing has to be completely duplicated. It's so expansive that C++ has gone out of its way to use pass-by-reference semantics, as well (now) RValue references.

D, on the other hand (being GC), has a "shallow ownership" philosopy: Basically, when you make a copy, nothing happens, appart from the binary copy of the object. You want to pass a string by value? that's 8 bytes of data. Period. The *most* complex CC I have *ever* seen in D merely increments a reference counter. That's it. 90% (99%?) of the time, there isn't even a postblit implemented. Because of this, D has embraced pass by value.

Not to mention, if you are using classes, those are already pointer types. Why pass them by ref?

--------

The conclusion is that the comparison is not fair: D's pass by value is not *very* different from C++'s pass by ref (in amount of data copied).

If you *do* want a fair-er comparison, then I'd suggest you implement a ".dup" on your object, and see how many times THAT gets called. Guess what: 0.

I'm not saying D's approach is perfect, just that D's library is optimized for D-like types.

Just the same, a lot the stl is not properlly optimized for little POD types, as they get passed around by ref, when their actual size is the same as the pointer referencing them...

Reply via email to