On Thursday, 3 July 2014 at 15:40:33 UTC, Wanderer wrote:
On Thursday, 3 July 2014 at 11:30:57 UTC, Alix Pexton wrote:
Saying that one is always more significant than the other is
far too much of an oversimplification.
I just thought, with the presence of structs in D, things are
not that simple. Structs don't use references and their
contents is located "right in place" if I understand this
correctly.
In other words, if you have array of structs, each struct of
100K size, and array's size is 10,000 elements, calling sort on
it would require shuffling 1 gigabyte of memory in the worst
case, stopping the entire application. (Sorting the same array
in Java would require shuffling only 40K of references and
would finish instantly, because only reference complex types
are allowed there.)
All I can say - yes, amount of swaps can be important in this
case of structs, but it's terribly inefficient anyway and
should be avoided IMHO.
Firstly, who uses 100kB structs? That's insanely large.
Secondly, sometimes you need the data to be contiguous in memory
after sorting, for performance or compatibility reasons.
The point where this is important is usually in a middle ground,
things like a complex type (std.complex.Complex can be as large
as 32 bytes IIRC) or a particle struct that holds position,
velocity and acceleration vectors.