What exactly is an 'aligned pointer'?

前端 未结 6 1935
执笔经年
执笔经年 2020-11-29 22:28

Would somebody please tell me what an aligned pointer actually means?

6条回答
  •  囚心锁ツ
    2020-11-29 23:08

    It is a pointer to an "aligned" address. Aligned in the sense that the address is a multiple of some value - typically, the sizeof whatever type of thing it will be pointing at (if a primitive type), or of some data member which requires such alignment.

    Usually you do not have to worry about this; memory allocation functions will ensure that the memory they give you is properly aligned. You start worrying about alignment at the point where you start doing unsafe things with pointer casts.

提交回复
热议问题