开发者

Class Packing and Alignment

What is the alignment for calling #pragma pack() with no argument in GCC compiler?

Also, I often see that when we use placement new in creating object, the class is often being packed. What is the reason for that? Is it necessary to do so开发者_如何学Python?


for the first part, you could have recklessly used google: http://gcc.gnu.org/onlinedocs/gcc/Structure_002dPacking-Pragmas.html

secondly there may be times when you need to control the binary format of your class. you may need to manage the amount of memory and the real binary offsets of data structures:

struct
{
  char c;
  int i;
};

may use 8 bytes of memory or 5 bytes of memory, according to machine type and pragma pack used.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜