Search code examples
c++memoryg++cygwinheap-memory

Heap size in C++ Cygwin


I need to allocate a lot of memory and I am fine with Cygwin use all my RAM. My installed RAM is 12GB. I have problem running the following code.

#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;
}

I receive a run-time error:

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

Which shows there is no enough memory. By reducing the allocated size the error disappears.

I use

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

But it seems regtool here cannot fix the problem while suggested in some websites.


Solution

  • arma::mat::fixed actually allocates the memory on the stack, which size is quite limited. It hunk that you should use the arma::mat constructor but I'm not sure because I never worked with arma.