c实现系统内存对齐

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/linxizi0622/article/details/73729586
#include <stdio.h>
#include <stdlib.h>
#define CHUNK_ALIGN_BYTES 8 
/* run this program using the console pauser or add your own getch, system("pause") or input loop */


int main(int argc, char *argv[]) {
	int size=41;
	if (size % CHUNK_ALIGN_BYTES) //8字节对其
            size += CHUNK_ALIGN_BYTES - (size % CHUNK_ALIGN_BYTES);
            printf("%d",size);
	return 0;
}
书上一直在说,数据总线是32位,所以保存在内存中的数据都需要进行内存地址对齐
但是不知道怎么实现,今天看书,发现其实也挺简单的,还是写上博客,做个笔记吧
 

猜你喜欢

转载自blog.csdn.net/linxizi0622/article/details/73729586