Stanislav,

You can change the stack size at least two ways;
1) change the requested stack size at build time in the 'pref' resource
2) change the actual stack at run time

The first is simple. For example, if using PilRC, the following is supposed
to work:

SYSAPPLICATIONPREFERENCES ID 0 PRIORITY 30 STACKSIZE 8192 MINHEAPSPACE 4096

Unfortunately, the above statement does not work in our version of PilRC, so
I use the following manual method:

HEX "pref" ID 0 /*priority*/0x00 0x1E /*minstack*/0x00 0x00 0x20 0x00
/*minheap*/0x00 0x00 0x10 0x00

The second is a hack, but works fine. Note, this method causes the emulator
to complain that the stack pointer is outside the stack boundaries. Turn
that warning off, of don't use the emulator.

How it works: you allocate the stack you'd prefer with MemPtrNew(), save the
current stack pointer, then change the stack pointer to point to the end of
the newly allocated stack, and call your code. When you return, restore the
stack pointer to the saved one, MemPtrFree() the one you created and return
to the original caller. It's easy in assembler. Example:

void asm ExecuteWithNewStack(void (*proc)(), UInt32 stackSize)
{

    // allocate new stack
    move.l   8(sp),-(sp)            // retrieve 'stackSize'
    trap     #15
    dc.w     #sysTrapMemPtrNew
    move.l   a0,(sp)                // save new stack base

    // call proc using new stack
    add.l    12(sp),a0              // add 'stackSize' to new stack pointer
    move.l   8(sp),a1               // retrieve 'proc'
    exg      a0,sp                  // exchange new and old stack
    move.l   a0,-(sp)               // save original stack pointer
    jsr      (a1)                   // call proc
    move.l   (sp)+,sp               // restore original stack pointer
 
    // dispose of allocated stack
    // previously allocated pointer is still on original stack
    trap     #15
    dc.w     #sysTrapMemPtrFree

    // cleanup and return
    lea      8(sp),sp
    rts

}

----- Original Message -----
From: "Stanislav Borisov"
Sent: Thursday, August 11, 2005 5:01 PM
Subject: Simple question about how to increase stack size

> Hi all,
> I'm new in the forum and in the Palm programming.
>
> I'm developing Palm application with CW9.0 for PalmOne Treo 650 device
and
now I'm testing with the simulator.
>
> I have following problem: Sometimes my application crashes with fatal
error "Invalid chunk ptr" or sometimes the simulator crashes comletely
without displaing this message. Without any changes in the code
sometimes my
application works fine, and sometimes crashes.
>
> I read all posts related with this "Invalid chunk ptr" error and try
lot
of things described there but nothing helps me.
>
> Please can somebody can explain me what can be the possible reasons
for
such type of crashes?
>
> Also if the stack size is too small can you tell me how I can increase
it?
>
> When I try to Debug application crashes in different places in the
code
and I can't understand where exactly is the problem. I have checked all
my
code for any memoty leaks but I didn't found anything wrong.
>
> My application has 3 segments, if this is significant.
>
> Please give me some advices, bocuse I'm stucked here. I will give you
more
info about my app if you need.
>
> Thanks in advance!!!
>
> --
 

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

Reply via email to