默认堆栈大小 [英] Default stack size

查看:90
本文介绍了默认堆栈大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Code :: Blocks中增加堆栈大小?

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

我已阅读及其表示VS中的默认堆栈大小为1MB.现在,就我而言,它与VS无关,并且堆栈大小取决于OS.以我的win10为例,它是1MB.

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.

似乎有点过时了,因为请遵循以下步骤: project->构建选项->链接器设置->其他链接器选项不再存在.

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

项目栏下没有构建.

无论如何,我需要增加堆栈大小,以便可以声明巨大的二维char数组并从缓存中受益.类似于 arr [1000] [1000] .因为它将位于连续内存中,而不像 char * arr [100] 那样,它将指向1000个不同的内存地址,其中包含1000个字节.

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.

我正在使用Windows 10 mingw编译器.

I'm using Windows 10 mingw compiler.

推荐答案

默认大小来自.exe,而不是操作系统.

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

来自 MSDN :

保留的和最初提交的堆栈内存的默认大小在可执行文件头中指定.

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

具体地说,在 IMAGE_OPTIONAL_HEADER 结构.通常可以使用链接器参数将其设置为特定值.使用MinGW工具链,您可以尝试使用 -Wl,-stack,52428800 这样的gcc参数.您正在使用的IDE中可能存在此选项,只需查找构建和/或链接器设置即可.

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.

这适用于第一个线程,如果在调用 CreateThread 时指定非零值,则其他线程可以覆盖默认值.

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

这篇关于默认堆栈大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆