Optimal struct layout template?

dsimcha dsimcha at yahoo.com
Fri Jan 9 08:09:17 PST 2009


== Quote from Don (nospam at nospam.com)'s article
> > For classes, the compiler can optimize the field layout by default.
> Well, it's very obscure, really. It only makes a difference when you
> want to reduce the size of the struct, since DMD already assigns padding
> to give optimal alignment. And you'd only use it in cases when you care
> about the size AND you don't think it's important enough to order the
> fields yourself (or where you can't, because you don't know the types)
> AND where you don't care that the compiler will add a few bytes of
> padding at the end.
> So I'm pretty much certain the compiler shouldn't include support for
> limited-interest stuff like this. I'm not even sure that it's useful
> enough to be in a standard library. It was a fun exercise though.

The thing is, those few bytes of padding really matter when you're working with
large arrays of templated structs, and they can turn into tens of megabytes, or
possibly even if they can just turn into kilobytes and kill cache performance.  A
perfect use for it (and the one I had in mind) was to build more space-efficient
generic hash tables.



More information about the Digitalmars-d mailing list