4 ms·
I'm not familiar with the "packing" concept. How does one go about manual packing? How does it affect maintenance?
by williadc 10y ago
I'm not familiar with the "packing" concept. How does one go about manual packing? How does it affect maintenance?
- blinkingled 10y agoCompilers typically align struct fields to a boundary to favor execution speed. This may be good for most use cases where there aren't thousands of instances of that struct wasting a lot of memory making it a bad tradeoff. So C/C++ compilers allow you turn this off either by specifying the data length yourself (bit fields) and/or specifying attribute(__packed__) directive in the case of GCC for example. In this case the packed directive resulted in suboptimal packing so they must have gone with bit fields I suppose to do manual packing.
- puzzle 10y agoOr you might also rearrange fields of the same type to be together.
- deleted 10y ago[deleted]
- Lozzer 10y agohttp://www.catb.org/esr/structure-packing/ http://www.catb.org/esr/structure-packing/