Memory Alignment role

1. In order to better cross-platform, reason: Some hardware can only be read from a specific memory address of a specific type of data, however, a different number of bytes occupied by each data, we need to uniformly aligned, that will compare easy to read, so the reason why C ++ is better cross-platform that is the case.
2. The speed up CPU access performance because the case is accelerated if a double or int type of data occupies four bytes, and then she is assumed that the number of bytes starting from the beginning of 1, the CPU reads it, it will have to 1 -44-8 then raised the number of bytes 1.5-8 2-5 and then into the register, so efficiency is greatly reduced, but for now the cpu, this should be nothing.
to sum up:

  • Basically today's machines require memory alignment of reasons, mainly because of better cross-platform
Published 382 original articles · won praise 122 · Views 400,000 +

Guess you like

Origin blog.csdn.net/Giser_D/article/details/104407039