C++ Cygwin 中的堆大小

Heap size in C++ Cygwin

我需要分配大量内存,Cygwin 可以使用我所有的内存。我安装的 RAM 是 12GB。我在以下代码中遇到问题 运行。

#include <iostream>
#include <armadillo>

using namespace arma;

int main()
{
    // arma::mat::fixed<10,10000> buffer; // ok
    arma::mat::fixed<10,100000> buffer; // cygwin_exception::open_stackdumpfile
    // arma::mat::fixed<10,100000000> buffer; // cygwin_exception::open_stackdumpfile
    std::cout<<"Allocation was successful."<<std::endl;
    return 0;
}

我收到 运行 次错误:

0 [unknown (0x1F40)] a 7656 cygwin_exception::open_stackdumpfile: Dumping stack trace to a.exe.stackdump

这说明内存不足。通过减少分配的大小错误消失。

我用

regtool -i set /HKLM/Software/Cygnus\ Solutions/Cygwin/heap_chunk_in_mb 2048
g++ main.cpp -larmadillo
a.exe

但似乎regtool这里不能解决某些网站建议的问题。

arma::mat::fixed 实际上是在栈上分配内存,其大小非常有限。你应该使用 arma::mat 构造函数,但我不确定,因为我从未使用过 arma。