C ++更改最大RAM限制 [英] C++ Change Max RAM Limit

查看:215
本文介绍了C ++更改最大RAM限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何更改程序的最大RAM数量?我经常耗尽内存(不是系统最大,ulimit最大),我不想改变全局内存限制。我看了看,看到vlimit()函数可能工作,但我不确定如何使用它。

How would I change the max amount of RAM for a program? I constantly am running out of memory (not system max, ulimit max), and I do not wish to change the global memory limit. I looked around and saw the vlimit() function might work, but I'm unsure exactly how to use it.

编辑:我在linux 2.6.38- 11-generic
这不是一个内存泄漏,我必须分配一个给定类的100k,没有办法。

I'm on linux 2.6.38-11-generic This is not a memory leak, I literally must allocate 100k of a given class, no way around it.

推荐答案

您是否在堆栈上分配对象,并且实际上是否达到堆栈限制?

Do you allocate the objects on the stack and are in fact hitting the stack limit?



Do you, e.g., write something like this:

void SomeFunction() {
    MyObject aobject[100000];
    // do something with myobject
}

堆栈。一个更好的解决方案 - 自动为你的堆分配 - 将是写

This array will be allocated on the stack. A better solution -- which automates heap allocation for you -- would be to write

void SomeFunction() {
    std::vector<MyObject> veccobject(100000); // 100.000 default constructed objects
    // do something with myobject
}

如果由于某种原因,你真的想要一个更大的堆栈,请查阅您的编译器文档的适当的标志:

If for some reason, you really want a bigger stack, consult your compiler documentation for the appropriate flag:

如何增加gcc可执行文件堆栈大小?

您可以设置调用堆栈的大小c ++? (vs2008)

您可能需要考虑:

什么时候担心堆栈大小?

这篇关于C ++更改最大RAM限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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