一些分配器是懒惰的吗? [英] Are some allocators lazy?

查看:26
本文介绍了一些分配器是懒惰的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Linux 中写了一个 C 程序,它 malloc 内存,循环运行,TOP 没有显示任何内存消耗.

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

然后我用那个内存做了一些事情,TOP确实显示了内存消耗.

then I've done something with that memory, and TOP did show memory consumption.

当我 malloc 时,我真的获得内存",还是有懒惰"的内存管理,只有在/当我使用它时才给我内存?

When I malloc, do I really "get memory", or is there a "lazy" memory management, that only gives me the memory if/when I use it?

(还有一个选项,TOP只知道我使用时的内存消耗,所以我不确定这个..)

(There is also an option that TOP only know about memory consumption when I use it, so I'm not sure about this..)

谢谢

推荐答案

在 Linux 上,malloc 使用 sbrk() 或 mmap() 请求内存 - 无论哪种方式,您的地址空间都会立即扩展,但 Linux 不会分配实际页面物理内存,直到第一次写入有问题的页面.您可以在 VIRT 列中看到地址空间扩展,而在 RES 中可以看到实际的物理内存使用情况.

On Linux, malloc requests memory with sbrk() or mmap() - either way, your address space is expanded immediately, but Linux does not assign actual pages of physical memory until the first write to the page in question. You can see the address space expansion in the VIRT column, while the actual, physical memory usage in RES.

这篇关于一些分配器是懒惰的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆