C ++变化最大内存的限制 [英] C++ Change Max RAM Limit
问题描述
我将如何改变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泛型
这不是一个内存泄漏,我硬是必须分配一个给定类的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?
你,例如,这样写:
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:
<一个href=\"http://stackoverflow.com/questions/625416/can-you-set-the-size-of-the-call-stack-in-c-vs2008\">Can设置在C ++中调用堆栈的大小? (VS2008)
你可能要考虑:
这篇关于C ++变化最大内存的限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!