Shop OBEX P1 Docs P2 Docs Learn Events
A simple question about Main RAM and Cog RAM — Parallax Forums

A simple question about Main RAM and Cog RAM

ElectricAyeElectricAye Posts: 4,561
edited 2008-09-20 18:12 in Propeller 1
Hi all,

I'm suddenly confused about how big my SPIN program is allowed to be. My current program is intended to run on just a single COG. Up till now I've been blithely writing code and, by using the Propeller Tool and the handy RAM usage panel, I've been watching how much memory space is being consumed by variables, etc.. and everything seemed to be within the limits displayed by the RAM usage panel. But now it occurs to me that maybe I've never truly understood how the Propeller executes code. I guess it's possible that a program might fit perfectly well within the RAM usage panel, but the Cog RAM of a single Cog might be way too small to run the program. Is this true?

Or, putting the question another way: when using only a single cog to run your application, must the ENTIRE program that is read from the Main RAM fit completely inside the cog RAM in order for that cog to run it? Or is there some kind of dance that takes place that writes part of the application out of Main Ram, runs it on the cog, then writes the next part of the application out of Main Ram, runs that part on the cog, and so on and so forth?

thanks,
Mark

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-09-20 05:04
    The Spin interpreter reads instructions one at a time out of main ram and interprets each completely before going on to the next. Most of the cog is occupied by the Spin interpreter itself along with a few longs of variables used by the interpreter.
  • ElectricAyeElectricAye Posts: 4,561
    edited 2008-09-20 05:15
    Mike,
    Okay, again you saved me from a late night panic attack. At least as a rough approximation, the RAM usage panel is therefore the first quick glance at how close to a memory problem a cog is likely to suffer.

    thank you!

    Mark
  • StefanL38StefanL38 Posts: 2,292
    edited 2008-09-20 06:01
    hello Amrk,

    as long as you program in SPIN a single cog can NOT suffer a out of COG-RAM memory problem. Because ALL COG-ram is ocupied by the SPIN-interpreter already.
    a SPIN-cog uses HUB-RAM for everything.
    IN SPIN it is the WHOLE CHIP who might have a out of memory-problem . Because all cogs SHARE the HUB-RAM of 32kB. And therefore it is regardless if one two or all eight cogs are running
    they SHARE the HUB-RAM. A cog running PASM-code has its own COG-RAM excusively for privat (2kB of COG-ram). Of course PASM-code can access
    HUB-RAM. This means for checking how much HUB-RAM is left you have to compile your TOP-Object-file and take a look on the RAM usage-panel.

    If you compile any relatied SUB-objectfile you will get a smaller result of RAM-usage because then only these parts are compiled that are needed by this SUB-object

    best regards

    Stefan
  • ElectricAyeElectricAye Posts: 4,561
    edited 2008-09-20 13:30
    Stefan,
    thank you for adding this comment. I was reading about assembly language when my original worry cropped up. Your explanation helps clarify some of my confusion between working with SPIN and working with assembly.

    have a good weekend,

    Mark smile.gif
  • Mike GreenMike Green Posts: 23,101
    edited 2008-09-20 15:25
    The RAM usage panel has no relationship whatsoever with cog memory usage or needs. It reflects hub RAM usage only. There is no equivalent display for cog RAM since the compiler has no good way to know how your program will be using cog RAM. The FIT statement is the closest thing and this simply allows you to specify how much cog memory you expect that portion of your program to use and the compiler does a simple check to see if it would fit.
  • ElectricAyeElectricAye Posts: 4,561
    edited 2008-09-20 18:12
    Hi Mike,
    that certainly helps complete the picture of how all this works.

    thank you!


    smile.gif
Sign In or Register to comment.