Sorting structs?

Stanislav Blinov stanislav.blinov at gmail.com
Wed Jan 29 02:12:10 PST 2014


It's also worth noting that you can avoid passing structs into
predicate function by value, and instead pass them by reference:

sort!((ref const a, ref const b) => a.grade > b.grade)(students);

This is useful for "heavy" structs to save on performance. E.g.
in this case, Student.sizeof is 24 bytes on 64 bit machine.
Passing by reference will only need to copy 16 bytes (i.e. size
of two pointers), whereas passing by value will incur copying 48
bytes (two structs).


More information about the Digitalmars-d-learn mailing list