The most likely cause of running out of stack space is you have infinite
recursion, i.e., a function calling itself over and over, or arrays.

Check for recursion first, that's what usually causes it, at least on the
PC.

Arrays also eat up stack space in a hurry.

UInt32 oneWhoppingBigArray[1000];     <- This will eat up 2k of stack space!

This is much better:
MemPtr array = MemPtrNew(1000*sizeof(UInt32));
UInt32* oneWhoppingBigArray = (UInt32*)array;

This will allocate the space for the array on the dynamic heap instead of
the stack.  Just remember to free it when you are done.  In this case the
only memory used by the stack is the memory to hold the MemPtr and the
UInt32 pointer, which is a total of... uh...8 bytes I guess.  Much better
than 2k.

Anytime you pass an argument to a function it is passed on the stack.
Anytime you create an object, it is created on the stack.  To allocate
memory in dynamic memory instead, use MemPtrNew and MemHandle.

If you are running out of stack space, increasing the size of the stack is
almost certainly not the correct answer.  You need to rework your code.

Matt Henry
www.iliumsoft.com


"Syed Najeebullah Hussaini" <[EMAIL PROTECTED]> wrote in message
news:92621@palm-dev-forum...
>
>
> How can i make the coding technique to be heap-intensive one.
> Also please do suggest where exactly i can increase the stack size in
> constructor..???
>
>
> Regards
>
>
> >Subject: Stack Overflow
> >From: "DNR" <[EMAIL PROTECTED]>
> >Date: Wed, 31 Jul 2002 10:00:54 +0600
> >
> >What are the known reasons for having the error "stack Overflow" ?
>
>         One known reason:  You've used too much stack!
>
>         You can increase it (using the Constructor) but probably
>         the problem is your coding techniques are stack-intensive
>         and will have to change to be heap-intensive instead.
>
> >This happens at different points in my function in different ROMs.
> >
> >Does it have anything to with using Classes (Object Oriented)
>
>         Modify your classes to use very little stack.
>         Use heap allocations/deallocations within your classes.
>         Avoid recursion.
>         Avoid arrays of objects.
>
> Roger Stringer
> Marietta Systems, Inc.
>
>
>
> --
> For information on using the Palm Developer Forums, or to unsubscribe,
> please see http://www.palmos.com/dev/support/forums/
>
>
>
>



-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/

Reply via email to