Shop OBEX P1 Docs P2 Docs Learn Events
SimpleIDE Cogc and Arrays — Parallax Forums

SimpleIDE Cogc and Arrays

I would LIKE to use an array in a cog using a .COGC file and have the values stored in the cog for rapid access. The normal way is to declare the array with something like int Tmp[10]; Unfortunately, this type of declaration causes the array to be stored in the HUB and results in numerous rd/wrlong instructions that takes many clock cycles to retrieve each value. Doesn't make for efficient code. Applying the _COGMEM attribute to the declaration generates an error message that the variable is not suitable to a single register. I have tried to initialize a contiguous set of values using the _COGMEM attribute then take the address of the first one but the compiler complains that a HUB variable is required. (NOTE: I realize the compiler may not store them as contiguous values I didn't get to the point that would be a problem).

Anyone have a suggestion for using a SimpleIDE .COGC file with data arrays where the array is stored in the Cog??

Comments

  • PropGCC will not let you use array syntax on cog memory. I'm not sure if you're familiar with how to iterate over an array in cog memory with assembly, but suffice it to say, it isn't easy/normal.
  • I was afraid that would be the case.
    I'm not familiar with the process but can learn. I was trying to get away from using assembly and stick with the C syntax.

    Thanks.
  • Heater.Heater. Posts: 21,230
    From what I remember from trying this kind of thing ages ago arrays in COG is a bit of a non-starter because:

    1) Arrays are all about eating space with data. There is precious little space in COG.

    2) Accessing arrays in COG can be done with self-modifying code. But then the overheads of doing that mean that using [RD,WR][BYTE, WORD, LONG] is about as quick. Especially if your array is actually bytes or words, which means you need to do shift/mask operations and such to get what you want.

    3) Like 2) but the code size overhead is intolerable.

    All in all, keep arrays in HUB.
Sign In or Register to comment.