Don't elements of structures are sorted before even packing starts? For example
char c;
int i;
char c2;
I thought in reality c2 starts after c. Instead of adding padding between each element, you will only need in boundaries
I thought in reality c2 starts after c. Instead of adding padding between each element, you will only need in boundaries
This is obviously not the default in C, but can be enabled via compiler extensions. It's also important that the compiler doesn't automatically do this since structs of the same type can be of different sizes. In order for this to work, the memory layout needs to be as originally defined in order to be correct. For an example of this see the simple dynamic string library used in redis.