Re:The Lost Art of C Structure Packing (2014)
by UncleEntity on Wednesday April 27, 2022 @02:53PM
(#31184197)
I know in blender there is a compile time check to ensure the structs are properly packed and it has nothing to do specific memory layouts.
I think it has to do with reading/writing them to disk but honestly never cared enough to ask anyone. Did make things convenient sometimes when you could ‘steal’ a padding value and magically got backwards compatibly because the older versions just ignored that field (and when reading an older file just set it to a sane default).
Re:The Lost Art of C Structure Packing (2014)
by pokey00 on Wednesday April 27, 2022 @11:08PM
(#31188346)
Yeah, I use them all the time for the specific memory layout part. At the same time, I've never had to go as far with optimization as trimming a few bytes off my structs for the program's memory footprint.
If that struct is getting written to storage or shoved over the wire though, I'll always optimize/pack them down, both for the size reduction and because it makes it easy to reconstruct on any other CPU.
I figure that's not the primary reason for structure packing, but rather for fine-grained control over writing to very specific memory layouts (think global descriptor table) as structs.