lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Tue, May 6, 2014 at 4:30 AM, Philipp Janda <siffiejoe@gmx.net> wrote:

> A very minor thing, but putting `hash` before `len` and `hnext` in the
> definition of `TString` saves 8 bytes per string on my machine where
> `sizeof( size_t) == 8` and `sizeof( unsigned int ) == 4` (Linux x86_64).
> This should be safe for all architectures where `sizeof( size_t ) >= sizeof(
> unsigned int )`, and I don't know if there are machines out there where this
> isn't true ...

Ooh good man :D  You know Java does something like automatic struct
member reordering to reduce padding like this.  This isn't done in
C/C++ because there is no standard defining how members should be
reordered, so it would vary from one compiler to another and binaries
wouldn't be portable across machines of the same architecture and
runtime.

I think it's mentioned in that "Deep C" PDF that floats around from
time to time..: http://www.slideshare.net/olvemaudal/deep-c

PS: Where is the hnext?
http://www.lua.org/source/5.2/lobject.h.html#TString  TString changes
in 5.3?  I'll have to look at my work copy...