Shop OBEX P1 Docs P2 Docs Learn Events
reserving specific memory address — Parallax Forums

reserving specific memory address

Erik FriesenErik Friesen Posts: 1,071
edited 2008-04-22 22:31 in Propeller 1
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[noparse][[/noparse]constant] or rdlong/wrlong variable,constant etc.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-04-22 13:59
    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.
  • Erik FriesenErik Friesen Posts: 1,071
    edited 2008-04-22 14:07
    So you would say If I did the _stack thing I could confidently smash and bang around on the end memory addresses?
  • Ken PetersonKen Peterson Posts: 806
    edited 2008-04-22 14:10
    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.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • Paul BakerPaul Baker Posts: 6,351
    edited 2008-04-22 22:31
    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
    Propeller Applications Engineer

    Parallax, Inc.
Sign In or Register to comment.