我在尝试调试一个程序进行分段故障时遇到了一种情况。我发现程序能够分配4GB的动态内存,而/ proc / meminfo中的可用内存只有1GB。请在下面找到程序和我的系统RAM信息。
#include<stdio.h>
#include<stdlib.h>
int main()
{
char *buf;
buf=malloc(1<<31);
fgets(buf,1024,stdin);
printf("%s\n",buf);
//return 1;
}
#vim /proc/meminfo
MemTotal: 1032984 kB
MemFree: 743620 kB
Buffers: 54156 kB
Cached: 175424 kB
SwapCached: 0 kB
Active: 91436 kB
Inactive: 158196 kB
HighTotal: 129440 kB
HighFree: 252 kB
LowTotal: 903544 kB
LowFree: 743368 kB
SwapTotal: 10241428 kB
SwapFree: 10241428 kB
Dirty: 0 kB
Writeback: 0 kB
Mapped: 32740 kB
Slab: 25748 kB
CommitLimit: 10757920 kB
Committed_AS: 74952 kB
PageTables: 1316 kB
VmallocTotal: 106488 kB
VmallocUsed: 7004 kB
VmallocChunk: 99300 kB
这个让我很困惑。请建议我。