Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
13 views
in Technique[技术] by (71.8m points)

c++ - Default stack size

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...