Monday, April 25, 2011

Can you set the size of the call stack in c++? (vs2008)

Im working from an example peice of code that allocates a relatively large local array. (32768 to be precise) When i try the same i'm getting behaviour that appears to be a stack overflow. Now i was wondering if my example has maybe set the stack to be larger then my application. Is this possible? if so how?

Many thanks

From stackoverflow
  • With the Microsoft compiler you can use /F to set the stack size, however it seems like you should just allocate the object on the heap. You should have a reason you're allocating this on the stack rather than the heap.

    Edit: This page gives a good cross-platform breakdown, though it may be dated.

    Adam Naylor : This is was very helpful, although it didn't fix the problem. Further investigation needed :(
    jeffamaphone : Maybe you should post a sample of your code in a new question.
    Adam Naylor : http://stackoverflow.com/questions/614842/why-does-this-code-corrupt-memory, already answered but setting the stack size hasn't fixed the problem so your thoughts would be appreciated
  • Rather than mess with with the stack size, why don't you simply use a std::vector or even dynamically allocate an array yourself?

  • You can use the /F compiler flag to set the default stack size, or specify it as the second parameter to the CreateThread function.

0 comments:

Post a Comment