【问题标题】:Memory in Linux [closed]Linux中的内存[关闭]
【发布时间】:2013-09-29 17:00:26
【问题描述】:

我的程序将数据从文件加载到结构中

std::tr1::unordered_map< Key, Details*> 

std::tr1::unordered_map< KeyOuter, std::tr1::unordered_map<KeyInner, Details*>* >
Key := std::string | int | long long
Details : struct { Fields } ( sizeof >=40 bytes )

我的程序定期从文件中读取新数据,然后回收旧结构。 (很多新建/删除操作)

在 windows 中: 重新加载数据后的内存使用量约为 200mb。

CentOS 中的相同文件:每次重新加载后的总内存使用量增加到 1000mb(内存使用量:200->400->600->800->1000->1000->1000-> 1000)

使用 vld 和 valngrind 未检测到泄漏。

如何在 Linux 中解决这个内存问题?

【问题讨论】:

  • 已解决。 malloc_trim() 调用 后内存返回到 os

标签: c++ linux memory allocation


【解决方案1】:

不是问题。 Linux 将您之前读取的文件保存在其缓存中,因此如果您需要再次读取它们,则无需访问 HDD。

此内存不会丢失,只要任何进程需要更多内存,它就会被释放。

有关详细信息,请参阅http://www.linuxatemyram.com/ 和 superuser.com 上的类似主题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-24
    • 2013-03-20
    • 1970-01-01
    • 2013-05-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多