Default stack size

半世苍凉 提交于 2021-02-04 12:36:26

问题


How can I increase the stack size in Code::Blocks?

I've read this and it says default stack size in VS is 1MB. Now as far as I am concerned, it has nothing to do with VS and stack size is OS dependent. In my win10 case it is 1MB.

This seems a little bit outdated as following this: project->build options->linker settings->other linker options doesn't exist no more.

There's no build under project bar.

Anyway, I need to increase my stack size so I can declare a huge two dimensional char array and benefit from cache. Like arr[1000][1000]. As it will be on contiguous memory unlike char* arr[100] which will point to 1000 different memory addresses containing the 1000 bytes.

I'm using Windows 10 mingw compiler.


回答1:


The default size comes from the .exe, not the OS.

From MSDN:

The default size for the reserved and initially committed stack memory is specified in the executable file header.

Specifically, the stack reserve and commit sizes are specified in the IMAGE_OPTIONAL_HEADER structure in a PE file. This can usually be set to a specific value with a linker parameter. With the MinGW toolchain you can try something like -Wl,--stack,52428800 as a gcc parameter. This option might exist in the IDE you are using, just look for build and/or linker settings.

This applies to the first thread, other threads can override the default if you specify a non-zero value when you call CreateThread.



来源:https://stackoverflow.com/questions/42420727/default-stack-size

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!