小编cho*_*zee的帖子

动态内存分配.我错过了什么?

请看一下这段代码:

#include <stdio.h>
#include <stdlib.h>

int main()
{
    char* foo = (char*)malloc(500000000);

    // when I uncomment stuff that's below then operating system
    // admits that this program uses 500MB of memory. If I keep
    // this commented, it claims that the program uses almost no
    // memory at all. Why is it so?

    /*
    for (int i=0; i<500000000; i++)
    {
        foo[i] = (char)i;
    }
    */

    int bar; scanf("%d", &bar); // wait so I can see what's goin on

    free(foo);

    return …
Run Code Online (Sandbox Code Playgroud)

c memory malloc operating-system

1
推荐指数
1
解决办法
366
查看次数

标签 统计

c ×1

malloc ×1

memory ×1

operating-system ×1