Блог пользователя FORHAD-SUST-BD

Автор FORHAD-SUST-BD, 12 лет назад, По-английски

Coin Change Dynamic Programming Problem and lot of Graph problems needed long depth recursion. That's why needed more than default stack size in c++. but i can't it. It is Possible to increase stack size in C++? I use c++ editor is Code Blocks 10.05.

Some programmer use in their code template is:

#pragma comment(linker, "/STACK: 2000000")

What is meaning of this part? Anyone can explain it?

  • Проголосовать: нравится
  • +1
  • Проголосовать: не нравится

»
12 лет назад, # |
  Проголосовать: нравится +12 Проголосовать: не нравится

As far as I know this feature works only in MS Visual C++. "/STACK:n" means that stack size is limited by n bytes. If you compile with GNU C++ the only way to increase the maximum stack size is to use a special compilation flag. You can see it here.

»
12 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится
  • »
    »
    11 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится
    • It works only in Linux and probably other Unix-like OSes. Codeforces runs your solution on Windows, and therefore this thing is unavailable.
    • If you're not root, you can only decrease limits, making yourself more and more limited. Obviously, nobody would run your solutions as root.
»
12 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Thank you @GeLo and @aram_gyumri

»
11 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

this command does not work in MSV C++ 2012. It displays the following error : error LNK1276: invalid directive '2000000' found; does not start with '/'

»
11 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Why do you want to do it in the program?

If you're just running the code on your computer (and use g++), then you can use -Wl,--stack,SIZE to set the size you wish for your run. Or ulimit on Linux.

If it's for a contest, you shouldn't do it. The stack size is the same for everyone (and it's usually mentioned in the rules). What you're doing is practically breaking into the testing system. You should just try to manage with the size that's set by default.