Optimal struct layout template?

Don nospam at nospam.com
Mon Dec 15 09:39:07 PST 2008


dsimcha wrote:
> == Quote from BCS (ao at pathlink.com)'s article
>> ??
>> http://en.wikipedia.org/wiki/Bin_packing_problem
> 
> Yes, but most structs are small enough that the asymptotic complexity really isn't
> important.  For structs of maybe 4 or less elements, trying every possible
> permutation in O(N!) seems perfectly reasonable to me.  For larger structs, using
> heuristics might be necessary.

You're only interested in the values of   x.sizeof&(x.alignof-1), and 
x.alignof is only ever 16,8,4,2, or 1. So there are only 65(?) possible 
elements.
I'm pretty sure it can be done in linear time, with the calculation 
maybe even done in constant time.



More information about the Digitalmars-d mailing list