Results 1 to 5 of 5
  1. #1
    monarch is offline Member
    Join Date
    Aug 2012
    Posts
    2
    Rep Power
    0

    Default How to cut down the stack size?

    hello,

    public void ShortestPath(int i)
    {

    if(!(nod.contains(i)))
    {
    k=0;
    nod.add(t, i);
    }


    while(k<node.elementAt(i).neighbours.size())
    {
    int a=node.elementAt(i).neighbours.elementAt(k);
    if( a!=dest && !(nod.contains(a)))
    {
    // pos.add(t, k);
    // t=t+1;
    ShortestPath(a);

    }
    k++;
    }
    System.out.println("t=" + k);
    }

    In my program, System.out.println("t=" + k); is executing multiple times i.e the number of times the Shortestpath(i) is called. Here, how can i make the size of the stack to null. Can i?

    thanks

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,242
    Rep Power
    19

    Default Re: How to cut down the stack size?

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default Re: How to cut down the stack size?

    how can i make the size of the stack to null
    What "stack" are you talking about?
    Object reference variables can be assigned a null value, primitives can not.
    If you don't understand my response, don't ignore it, ask a question.

  4. #4
    monarch is offline Member
    Join Date
    Aug 2012
    Posts
    2
    Rep Power
    0

    Default Re: How to cut down the stack size?

    Quote Originally Posted by Norm View Post
    What "stack" are you talking about?
    Object reference variables can be assigned a null value, primitives can not.
    Thanks for your response.

    I meant stack is called whenever the function calling to itself and the rest of the code following the function call is placed in the stack. here, in my problem the function is calling twice and so two times the following code is placed in stack. And so is the reason, 'System.out.print' is executing twice. I do not want that to happen and i.e., i should not be bothered about the stack.

    hope you understand.

    Thanks

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default Re: How to cut down the stack size?

    The only time you should be bothered by the stack is when you use too much of it with a recursive method and it runs out of space.

    If you don't like the way your code executes you should change it so it does what you want.

    One way to skip out of the call stack could be to wrap the code in a try{} catch block and throw an exception when you want to pop up a bit. Never needed to do it, so am not sure if it would work.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Replies: 2
    Last Post: 01-14-2012, 08:56 PM
  2. Increasing heap/stack size (MacOSX)
    By CapsLoc in forum New To Java
    Replies: 3
    Last Post: 12-13-2010, 10:52 AM
  3. Changing the stack size
    By saif.hakim in forum New To Java
    Replies: 1
    Last Post: 04-26-2009, 06:58 AM
  4. Replies: 3
    Last Post: 09-27-2008, 04:46 AM
  5. How to set a stack size. -Xss doesn't work
    By protonus in forum New To Java
    Replies: 4
    Last Post: 06-27-2008, 06:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •