FORHAD-SUST-BD's blog

By FORHAD-SUST-BD, 12 years ago, In English

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?

  • Vote: I like it
  • +1
  • Vote: I do not like it

»
12 years ago, # |
  Vote: I like it +12 Vote: I do not like it

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 years ago, # |
  Vote: I like it 0 Vote: I do not like it
  • »
    »
    11 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it
    • 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 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Thank you @GeLo and @aram_gyumri

»
11 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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.