urz*_*eit 1 c linux malloc memory-management
在一台64位的linux机器上,我编写了以下小型C程序:
#include <stdlib.h>
#include <stdio.h>
int main (void)
{
#define BLOCK_SIZE (1024*1024)
int i;
for (i = 1; ; i++)
{
char *p = (char *)malloc(i * BLOCK_SIZE);
if (p == 0)
break;
*p = 13;
free(p);
}
printf ("Allocated max %d MB\n", (i - 1));
return 0;
}
Run Code Online (Sandbox Code Playgroud)
如果我编译它-O0 -m64,我可以在我的桌面系统上分配2047 MB.如果我使用-O0 -m323829 MB 编译相同的程序.
为什么32位二进制文件的最大malloc大小比同一台机器上的64位二进制文件大?
编辑:如果我激活优化器-O3,64位机器上的最大内存量为20588.
| 归档时间: |
|
| 查看次数: |
973 次 |
| 最近记录: |