Dat vs Var and address
This seems like such a basic question and yet I can't seem to find a clear answer.
I have a variable array that needs to be visible to a wide range of routines (ServoStage). Currently, I pass the address and the number of elements and then play decoding games with BYTE. From what I'm reading, the DAT block is "global" among cogs, so there is only one instance. So my scheme seems to work, but it looks clumsy.
I can define an array in VAR (IncomingSpeed) but that is local to this object and if I happen to have two of them, I get two copies (not good). But it does look cleaner from a coding standpoint.
Is there a more elegant way to pass an array ?
If not, is it worth copying the array to a local variable, and then putting it back. ? Something like ByteMove[noparse][[/noparse]ServoState,IncomingSpeed, 6] ? What do I lose in speed ?
Can I move bytes between objects defined "differently" ?
I'm presuming their is no way to "map" a data structure on top of an address. (but hey; correct me if I missed that)
DAT
ServoState Byte 1, 1, 1, 1, 1, 1 'Values to be sent
Var
Byte IncomingSpeed[noparse][[/noparse]6] ' Values from input
I have a variable array that needs to be visible to a wide range of routines (ServoStage). Currently, I pass the address and the number of elements and then play decoding games with BYTE. From what I'm reading, the DAT block is "global" among cogs, so there is only one instance. So my scheme seems to work, but it looks clumsy.
I can define an array in VAR (IncomingSpeed) but that is local to this object and if I happen to have two of them, I get two copies (not good). But it does look cleaner from a coding standpoint.
Is there a more elegant way to pass an array ?
If not, is it worth copying the array to a local variable, and then putting it back. ? Something like ByteMove[noparse][[/noparse]ServoState,IncomingSpeed, 6] ? What do I lose in speed ?
Can I move bytes between objects defined "differently" ?
I'm presuming their is no way to "map" a data structure on top of an address. (but hey; correct me if I missed that)
DAT
ServoState Byte 1, 1, 1, 1, 1, 1 'Values to be sent
Var
Byte IncomingSpeed[noparse][[/noparse]6] ' Values from input
Comments
2) If you want to access a variable (array, scalar, whatever), in some other object, you pass its address (with "@") to a routine in that other object. That routine can save a local copy of the address or you can pass it whenever a routine is called that requires it. Both schemes have been used. You reference that variable by using "BYTE[noparse][[/noparse] address ]" or "WORD[noparse][[/noparse] address ]" or "LONG[noparse][[/noparse] address ]". If the variable is an array, you can use something like "BYTE[noparse][[/noparse] address ] [noparse][[/noparse] i ]".
Thats what I have. Just makes the code look ugly. But if it is independent, then the BYTEMOVE[noparse][[/noparse]target, source, number] should work ?
Thanks for the quick answer.
This notation is bulky and relatively inefficient (takes more memory and time than local accesses to variable names). I've written large programs using it and sometimes converted back to making local copies of the variables when they're just scalars. LONGMOVE is very fast if the data is long-aligned.
Thanks again