View Full Version : reserving specific memory address
04-22-2008, 08:38 PM
Is there a way I can reserve a specific memory address in main memory?· When you have three or so cogs that you have to pass multiple pointers so they share certain variables it seems like it would be much simpler to reserve a few spots and just make constants in each cog with the address number, then long[constant] or rdlong/wrlong variable,constant etc.
04-22-2008, 08:59 PM
There's no way to reserve specific memory locations. Since programs are allocated memory from 0 to higher addresses and the stack expands to higher addresses, you can assign locations beginning at the end of memory ($7FFF) towards 0. The only place where you'll get into trouble is if you use the graphics driver which does the same sort of thing for its bitmaps.
04-22-2008, 09:07 PM
So you would say If I did the _stack thing I could confidently smash and bang around on the end memory addresses?
04-22-2008, 09:10 PM
One thing I usually do is to set aside variables in the VAR (or DAT) section and set pointers to them in the DAT section. Then I use an init routine to set the pointers to point to their corresponding variables before launching the cogs. Make sure your pointer is within 496 bytes of the start of your cog code. Then when you launch the cog, the pointer gets copied to cog memory along with the code.
04-23-2008, 05:31 AM
The way Spin and the compiler work it is more robust to pass pointers around, create the space in VAR or DAT in your top level object and pass the pointer down to the objects that need access. Hard coding address space can create portability problems if you try to reuse the object in another project.
Paul Baker (mailto:firstname.lastname@example.org)
Propeller Applications Engineer
Parallax, Inc. (http://www.parallax.com)