Memory Alignment

Memory Alignment depicts how the data shown be stored in the computer’s memory. Although most architectures align data in consecutive manner and even adjust misalignment (like x86), programmers should not solely depend on this assumption.

Because of the memory alignment, in #c and #cpp, we could access stored data directly by using union structure which contains unsigned char array.

Links to this page
  • alignas and alignof

    alignas and alignof are 202203061200# keywords in C and C++. The first helps to position objects on cache boundaries which could improve memory access in certain cases. The latter can be used to check the memory alignment of the object.

#memory #container #c #cpp #rust