Shop OBEX P1 Docs P2 Docs Learn Events
How much stack is nessisary for COGNEW and how can you determine it? — Parallax Forums

How much stack is nessisary for COGNEW and how can you determine it?

MicrocontrolledMicrocontrolled Posts: 2,461
edited 2009-11-16 03:01 in Propeller 1
If you are trying to start an object or another PUB routine in a COGNEW or COGINIT then how much "stack" is needed and how can you determine based on the PUB/PRI routine? Sorry for being·clueless......blush.gif

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Computers are microcontrolled.

Robots are microcontrolled.
I am microcontrolled.

But you·can·call me micro.

Want to·experiment with the SX or just put together a cool project?
SX Spinning light display·
Want cheap wholesale electronic parts?
Transistor parts wholesale

Comments

  • AleAle Posts: 2,363
    edited 2009-11-15 21:23
    From what I saw (BST list of compiled code) you need 2 longs of stack.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Visit some of my articles at Propeller Wiki:
    MATH on the propeller propeller.wikispaces.com/MATH
    pPropQL: propeller.wikispaces.com/pPropQL
    pPropQL020: propeller.wikispaces.com/pPropQL020
    OMU for the pPropQL/020 propeller.wikispaces.com/OMU
  • Mike HuseltonMike Huselton Posts: 746
    edited 2009-11-15 21:29
    Stack requirement varies, based on code usage and buffer lengths. An object in OBEX helps the computation of stacks: obex.parallax.com/objects/25/.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    JMH
  • w8anw8an Posts: 176
    edited 2009-11-15 21:31
    From the "Propeller Education Kit Lab- Fundamentals v1.1" in section "Methods and Cogs Lab"

    Err on the side of caution: The best way to set aside stack space for a cog that gets a Spin method launched 
    into it is to err on the side of caution and declare way more memory that you think you’ll need.  Then, you can 
    use an object in the Propeller Tool’s object library  (the folder the Propeller.exe file lives in) named 
    Stack Length.spin to find out how many variables the method actually used.  The Objects Lab will feature a 
    project that uses the Stack Length object to verify the number of long variables required for a Spin method that 
    gets launched into a cog.
    
    NOTE: The instructions for using the Stack Length object are hidden in its THEORY OF OPERATION comments, which are 
    visible in documentation view mode.
    
    



    I would recommend reading this Method and Cogs Lab as there is additional information about using the stack.

    --Steve
  • ericballericball Posts: 774
    edited 2009-11-15 22:41
    In http://forums.parallax.com/showthread.php?p=605558Mike Green said...
    Any call on a method (function or procedure) requires a long for the return address information. This may include the pointer to the previous stack frame or that may take a second long. Chip will have to chime in here on that. A long for the return value is always allocated. If the called method declares local variables, each one will take an additional long. If the called method has any parameters, a long for each will be allocated in the caller's stack frame. Expressions use the stack for evaluation, so they may cause the use of additional levels of the stack.
    So as a start you need to walk through your code and build a call tree and note the number of parameters and local variables along with any complex expressions.· If you use recursion you will need to determine how deep that might go.· You might be surprised how much stack you are using.



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Composite NTSC sprite driver: Forum
    NTSC & PAL driver templates: ObEx Forum
    OnePinTVText driver: ObEx Forum
  • MicrocontrolledMicrocontrolled Posts: 2,461
    edited 2009-11-16 02:30
    Thanks for the info, however, I am not talking about "stack" in the since that you think I am. When I say "stack" I mean the variable pointer that is called here:
    
    cognew(MyPubRoutine, @stackvar)
    
    
    


    The variable it points to is the one that I am talking about, not at all the kind that you store at the top of your program for something like a video buffer.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Computers are microcontrolled.

    Robots are microcontrolled.
    I am microcontrolled.

    But you·can·call me micro.

    Want to·experiment with the SX or just put together a cool project?
    SX Spinning light display·
    Want cheap wholesale electronic parts?
    Transistor parts wholesale
  • Mike GreenMike Green Posts: 23,101
    edited 2009-11-16 03:01
    It's the same thing. Each cog that's executing a Spin program requires its own stack area. The main (default) cog has an implicit stack that starts at the end of the program and continues upward in memory (and will overwrite any video buffers placed at the end of memory if it grows too big). For cogs other than the default one, you have to supply the address of an area to be used for the stack for that cog's Spin interpreter and the 2nd parameter of COGNEW is that address.
Sign In or Register to comment.