中断系统调用posix_memalign

中断系统调用posix_memalign

问题描述:

我得到这个例外有posix_memalign。任何想法,为什么我们得到它?

I am getting this exception with posix_memalign. Any idea as to why we get it?

先谢谢了。

此问题已解决的问题:事情是对齐边界应该是2的倍数和的sizeof(无效*)。所以,如果posinter大小为4个字节,第二个参数应该是4,8,16等相反,我是把它作为唯一的2的倍数,因此它崩溃。

The issue is resolved: The thing is the alignment boundary should be a multiple of 2 and sizeof(void *). So if posinter size is 4 bytes, the second argument should be 4, 8, 16 etc. Instead of that i was putting it as only multiple of 2, and hence it was crashing.

Wrong usage: crashes
posix_memalign(&addr, 2, 8);

Correct usage:
 posix_memalign(&addr, 4, 8); // Second argument multiple of void* and 2