Shop OBEX P1 Docs P2 Docs Learn Events
cog memory assignment — Parallax Forums

cog memory assignment

shmowshmow Posts: 109
edited 2008-09-10 14:18 in Propeller 1
Hello,
what is the best way to check if you are using enough memory assigned to a cog?

Here is what I've done and I don't really know if it's an efficient way to do it:

I have six cogs running simultaneously; each with a different amount of memory assigned.

I've assigned memory this way...
- After I "View Info" (F8) I can click on any block of code to see the amount of memory it uses (listed in bytes displayed at bottom of screen).
- I divide this value of bytes by four to figure out how much memory it is in long.
- Finally, I know that the prop can hold 5240 long of code so I just subtract each amount of long each block of code takes up (plus a little·added padding.)

For example...
...a block of code takes up 400 bytes of memory...
...I divide this by 4 to get the equivalent of the amount of code - 100 long...
...I then double this value to 200... (just in case - extra padding)...
...finally, this block of code is "mapped" to a memory location of 5140 (5240-100=5140)
· ie··· cognew(Wireless_Input, @stack[noparse][[/noparse]5140]).

Is this a good way to manage this?

Thanks,
Shmow

Comments

  • AleAle Posts: 2,363
    edited 2008-09-10 14:16
    The cogs have their own memory and it is not mapped in HUB memory. A portion of HUB memory is COPIED to COG's memory (always 512 longs) when a cog is launched (with cognew)

    Edit: Was he talking about the stack ?... well, my bad. freaked.gif

    Post Edited (Ale) : 9/10/2008 2:36:45 PM GMT
  • Mike GreenMike Green Posts: 23,101
    edited 2008-09-10 14:18
    There's an object in the Propeller Object Exchange (obex.parallax.com/objects/25/) that runs in its own cog and monitors the actual stack usage of another cog. I suggest you use this to determine the approximate stack usage of each of your cogs, then add a safety factor, perhaps 20 longs, and use that. There are ways to go through your code and estimate the amount of stack space used, but this rapidly becomes unmanageable as your cog programs become more complex.

    I recommend you use a separate stack array for each cog (like "Wireless_Input_Stack", "Other_Cog_Stack")
Sign In or Register to comment.