Containers
Per Nordlöw
per.nordlow at gmail.com
Wed Sep 1 10:25:47 UTC 2021
On Wednesday, 1 September 2021 at 02:08:40 UTC, max haughton
wrote:
> layout. The most profitable example of that I can think of is
> automatically switching arrays of POD types to be a struct of
> arrays internally. This transformation makes random access to
> elements slower, however (say) loops where access to a subset
> of the elements dominates then this is much faster due to
> improved cache efficiency.
Speaking of which, here's my D implementation of struct of arrays
(SoA):
https://github.com/nordlow/phobos-next/blob/master/src/nxt/soa.d
Peter Kirov has an alternative implementation providing some
benefits. I've copied it into
https://github.com/nordlow/phobos-next/blob/master/src/nxt/soa_petar_kirov.d
The two implementations should be united.
Note that Petar's SoA-implementation has its `capacity`-property
functionally deduced from the `length` property as
```d
/** Returns the current capacity - the current length rounded up
to a power
of two. This assumption allows us to save on having a
separate field.
*/
size_t capacity() const pure @safe
{
return _length.roundUpToPowerOf2;
}
```
thereby saving a word of (stack) space. That behaviour could be
opt-in aswell via a template parameter.
More information about the Digitalmars-d
mailing list