Are some allocators lazy?

后端 未结 6 1567
遇见更好的自我
遇见更好的自我 2020-11-27 21:34

I wrote a C program in Linux that mallocs memory, ran it in a loop, and TOP didn\'t show any memory consumption.

then I\'ve done something with that memory, and TOP

6条回答
  •  感情败类
    2020-11-27 22:09

    Yes, note the VirtualAlloc flags,

    MEM_RESERVE
    MEM_COMMIT
    

    .

    Heh, but for Linux, or any POSIX/BSD/SVR# system, vfork(), has been around for ages and provides simular functionality.

    The vfork() function differs from fork() only in that the child process can share code and data with the calling process (parent process). This speeds cloning activity significantly at a risk to the integrity of the parent process if vfork() is misused.

    The use of vfork() for any purpose except as a prelude to an immediate call to a function from the exec family, or to _exit(), is not advised.

    The vfork() function can be used to create new processes without fully copying the address space of the old process. If a forked process is simply going to call exec, the data space copied from the parent to the child by fork() is not used. This is particularly inefficient in a paged environment, making vfork() particularly useful. Depending upon the size of the parent's data space, vfork() can give a significant performance improvement over fork().

提交回复
热议问题