Memory alignment check

前端 未结 3 1170
闹比i
闹比i 2021-02-01 21:34

I want to check whether an allocated memory is aligned or not. I am using _aligned_malloc(size, align); And it returns a pointer. Can I check it by simply dividing

3条回答
  •  眼角桃花
    2021-02-01 22:08

    Memory returned by malloc is aligned for everything (ie, it generally uses the an alignment that works for everything)*. That means, if you have an alignment issue, it is something else.

    http://www.delorie.com/gnu/docs/glibc/libc_31.html

    http://msdn.microsoft.com/en-us/library/ms859665.aspx

    (There appears to be exceptions for higher orders of alignment, which is an unusual requirement anyway.)

提交回复
热议问题