4 ms·
"a technique for reducing the memory footprint of programs in compiled languages with C-like structures" I figure that's not the primary reason for structure p
by hnur 4y ago
"a technique for reducing the memory footprint of programs in compiled languages with C-like structures"
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.
- UncleEntity 4y agoI 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).
- pokey00 4y agoYeah, 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.