查找当前系统cache line大小:cat /sys/devices/system/cpu/cpu1/cache/index0/coherency_line_size
函数:void * memalign (size_t boundary, size_t size) 头文件stdlib.h
函数memalign将分配一个由size指定大小,地址是boundary的倍数的内存块。参数boundary必须是2的幂
释放内存:free函数
还有一说是用void *aligned_alloc(size_t alignment, size_t size);头文件stdlib.h
- 参数size是申请的内存大小;
- 参数alignment为内存对齐大小,必须是2的幂
但是该函数是C11函数,因此在gcc版本较低时编译会报错,因此笔者建议使用上面那个函数
释放内存:free函数
声明64字节对齐数组:char __attribute__((aligned(64))) position_cell[POSITION_NUM][27]