Unnecessary struct padding
Unnecessary struct padding
- Subject: Unnecessary struct padding
- From: Benjamin Rister <email@hidden>
- Date: Mon, 22 Aug 2011 18:15:44 -0400
I’ve got a situation where I’ve got a huge number of things I want to fit in memory without chomping up all of the user’s RAM, so I’m trying to optimize the data structure down as much as possible. I’m running into issues where it appears the compiler (LLVM 2.0) is padding things that don’t seem to need to be padded for alignment.
The struct looks like this. I’ve marked the places where it’s being padded unnecessarily:
struct MyStruct {
MyStructRef; // 8 bytes
NSTimeInterval; // 8 bytes
// Collectively, 8 bytes
UInt8[3];
UInt8[3];
UInt8;
UInt8;
union {
struct {
struct MyStruct **; // 8 bytes
union {
id;
char[20];
// XXX: 4 bytes of unneeded padding here, as the UInt32 next is already 4-byte aligned
};
UInt32;
// XXX: 4 bytes of unneeded padding here, since the UInt8 next has no alignment needs
};
struct {
union {
id;
char[12];
// XXX: 4 bytes of unneeded padding here, as the UInt8s next have no alignment needs
};
UInt8[20];
}; // XXX: 4 bytes of unneeded padding here, since the UInt8 next has no alignment needs
}
UInt8;
// I know there’s some slack here because malloc works in 8-byte intervals…this is a work in progress
};
Am I forgetting some rule about alignment or something that makes this padding legitimate or needed? My first choice would not be to disable the compiler’s padding altogether, because while it all lines up now, I don’t want to accidentally break it later without noticing—and if I’m forgetting a reason why this would be needed, just disabling it already could break something. Any suggestions?
Thanks,
br _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden