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

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

问题描述

我在Linux上编写了一个C程序,该程序可以分配内存,并在一个循环中运行它,而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.

当我分配内存时,我真的是获取内存",还是有一个惰性"内存管理,仅在使用时才给我内存?

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时,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天全站免登陆