```#include
int main() {
std::array
std::cout << "Test" << std::endl;
return 0;
}
I compiled and run the above with `g++ main.cpp && gdb a` then typing run.
Output:
Starting program: C:UsersjohnWorkTestingsrca.exe
[New Thread 7044.0x2f20]
[New Thread 7044.0x740]
[New Thread 7044.0x1634]
[New Thread 7044.0x2974]
Thread 1 received signal SIGSEGV, Segmentation fault.
0x00007ff904fe26c4 in WriteFile () from C:WindowsSystem32KernelBase.dll
```
When the size is set to 518212, it works fine but when set to 518213, it segfaults.
It will allocate up to 2,072,848 bytes but segfault on 2,072,849 (tested by switching the type to char).
CRT is mingw-w64-x86_64-crt-git 6.0.0.5100.739199f8-1
GCC is mingw-w64-x86_64-gcc 7.3.0-1
I think this may be related to issue #1104
There are limits to how much stack space is available (to a function). The default seems to be 2M.
Via googling: you can apparently increase it with -Wl,--stack,<size>.
Also, i believe, if you put it as a global variable the compiler will do this automatically, but not inside a function.
I don鈥檛 think this is related to #1104.
There are limits to how much stack space is available (to a function). The default seems to be 2M.
Via googling: you can apparently increase it with -Wl,--stack,.
Also, i believe, if you put it as a global variable the compiler will do this automatically, but not inside a function.
I don鈥檛 think this is related to #1104.
I feel like an idiot. I forgot that std::array allocates to the stack and not the heap. I was thrown off when the same code that I wrote the minimal case from worked just fine in my Arch VM at work but not my Windows machine at home so I thought it might have been an implementation issue with mingw-w64.
Why is the stack so low? On my Arch VM, the code must have been using about 4MB with no issue. I'll bump it up anyway or maybe swap it out for a vector. Might profile both and see which is better. Thanks @Optiligence :+1:
@MenaceInc : as the problem seems solved, please close this issue, to avoid accumulating lots of open issues. Thanks.
@oscarfv the question regarding why the stack in MinGW-w64 is low compared to gcc on Arch was unanswered but I'll agree to close the issue as I feel like I won't get an answer.
@MenaceInc : different platforms, different defaults.
BTW, this is not a GCC thing, this is a binutils (linker) platform-dependant property. If unset, the process gets the OS default (2 MB). MS linker defaults to 1 MB for new threads. See https://msdn.microsoft.com/en-us/library/windows/desktop/ms686774(v=vs.85).aspx
@oscarfv I appreciate the explanation, thank you.
Most helpful comment
There are limits to how much stack space is available (to a function). The default seems to be 2M.
Via googling: you can apparently increase it with
-Wl,--stack,<size>.Also, i believe, if you put it as a global variable the compiler will do this automatically, but not inside a function.
I don鈥檛 think this is related to #1104.