6 Replies - 2570 Views - Last Post: 12 February 2013 - 06:16 AM Rate Topic: -----

#1 chrisreaper  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 26
  • Joined: 27-September 11

How to Increase Stack Size in Visual Studio 2010

Posted 30 January 2013 - 05:39 PM

How do I increase the stack size for my C++ program in Visual Studio 2010? I really cannot figure this out. I tried doing this http://msdn.microsof...v=vs.80%29.aspx but it didn't make any sense to me. I need to know this because my program will not do my recursion without it. Thanks in advanced!
Is This A Good Question/Topic? 0
  • +

Replies To: How to Increase Stack Size in Visual Studio 2010

#2 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: -4
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: How to Increase Stack Size in Visual Studio 2010

Posted 30 January 2013 - 06:29 PM

Any chance of posting your code? You shouldn't need to do this with your program.
Was This Post Helpful? 1
  • +
  • -

#3 jjl  Icon User is offline

  • Engineer
  • member icon

Reputation: 1051
  • View blog
  • Posts: 4,458
  • Joined: 09-June 09

Re: How to Increase Stack Size in Visual Studio 2010

Posted 30 January 2013 - 07:26 PM

Quote

I need to know this because my program will not do my recursion without it.

If you are blowing through all of your stack space, then maybe you should look into doing whatever it is your doing iterativly.

Are you required to use recursion?
Was This Post Helpful? 0
  • +
  • -

#4 undefined behaviour  Icon User is offline

  • New D.I.C Head

Reputation: 7
  • View blog
  • Posts: 36
  • Joined: 17-January 13

Re: How to Increase Stack Size in Visual Studio 2010

Posted 30 January 2013 - 09:14 PM

Perhaps a stack data structure with nested loops can solve your problem without using any callstack space, and without non-portable callstack hacks.
Was This Post Helpful? 0
  • +
  • -

#5 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5643
  • View blog
  • Posts: 12,359
  • Joined: 16-October 07

Re: How to Increase Stack Size in Visual Studio 2010

Posted 31 January 2013 - 05:30 AM

You shouldn't need to. If you're blowing the stack, then you have a design issue.
Was This Post Helpful? 0
  • +
  • -

#6 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3180
  • View blog
  • Posts: 9,645
  • Joined: 05-May 12

Re: How to Increase Stack Size in Visual Studio 2010

Posted 31 January 2013 - 06:10 AM

A design issue, or an oversight in coding. For example, this is a quick way to blow you stack:
void StackBlowingInOrderTreeWalk(Node * pnode)
{
    if (!pnode)
        return;

    StackBlowingInOrderTreeWalk(pnode->pnodeLeft);

    //$ BUG: 4K buffer on the stack. Tree height of 16 will
    //       overflow the default 64K stack in Windows. 
    char buffer[4096];
    sprintf(buffer, "%d\n", pnode->nData); 

    StackBlowingInOrderTreeWalk(pnode->pnodeRight);
}


Was This Post Helpful? 0
  • +
  • -

#7 undefined behaviour  Icon User is offline

  • New D.I.C Head

Reputation: 7
  • View blog
  • Posts: 36
  • Joined: 17-January 13

Re: How to Increase Stack Size in Visual Studio 2010

Posted 12 February 2013 - 06:16 AM

View Postbaavgai, on 31 January 2013 - 05:30 AM, said:

You shouldn't need to. If you're blowing the stack, then you have a design issue.


Was that a response to my suggestion to use a stack data structure with nested loops instead of recursion? Implementing a stack data structure with nested loops instead of recursion would be one example of reconsidering the design. If reconsidering the design doesn't prevent blowing the stack, then what will?

Here's my rough attempt at Skydiver's inorder tree walk, using a stack data structure and nested loops instead of recursion.
struct stack {
    Node *node;
    struct stack *next;
};

Node *stack_push(struct stack **stack, Node *node) {
    struct stack *n = malloc(sizeof *n);
    if (n == NULL) { return node; }
    n->node = node;
    n->next = *stack;
    *stack = n;
    return node;
}

Node *stack_pop(struct stack **stack) {
    if (*stack == NULL) { return NULL; }
    Node *node = *stack->node;
    struct stack *next = *stack->next;
    free(*stack);
    *stack = next;
    return node;
}

void InOrderTreeWalk(Node * pnode)
{
    struct stack *s = NULL;

    while (pnode) {
        if (pnode->pnodeLeft) {
            pnode = stack_push(&s, pnode)->pnodeLeft;
            continue;
        }

        do {
            char buffer[4096];
            sprintf(buffer, "%d\n", pnode->nData);

            if (pnode->pnodeRight) {
                pnode = pnode->pnodeRight;
                break;
            }

            pnode = stack_pop(&s);
        } while (pnode);
    }
}


This post has been edited by undefined behaviour: 12 February 2013 - 06:20 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1