Array of bytes as a local variable
Mightor
Posts: 338
Hey there,
I looked around in the Prop manual but I couldn't find any reference to it, so I thought I'd ask here.
Is it possible to declare a local variable that's an array of bytes? I am looking to use it inside a single function only. The idea is that I have a single cog that takes care of the servo of the PING))) sensor and takes readings at the same time. I want to build a map of its surroundings by dividing the full 128 brads into 16 sections, giving me 17 readings in total. This map should only be passed down once a single pass has been made (from left to right or from right to left) but I still want an older copy of the map to be available to the rest of the system while the Radar object works on a new version. I intended to bytemove to copy my local array to the global one. I would have make sure that the underlying system checks a "busy" flag before it consults the map (or before I write a new map to it). The busy flag would be a kind of semaphore. I am aware of the fact that SPIN can do semaphores but I am not familiar enough with those yet to be able to use them yet. Maybe in the next version.
So, is this possible or will I need to just use an Object wide array for this purpose?
Gr,
Mightor
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
| Any sufficiently advanced technology is indistinguishable from magic.
I looked around in the Prop manual but I couldn't find any reference to it, so I thought I'd ask here.
Is it possible to declare a local variable that's an array of bytes? I am looking to use it inside a single function only. The idea is that I have a single cog that takes care of the servo of the PING))) sensor and takes readings at the same time. I want to build a map of its surroundings by dividing the full 128 brads into 16 sections, giving me 17 readings in total. This map should only be passed down once a single pass has been made (from left to right or from right to left) but I still want an older copy of the map to be available to the rest of the system while the Radar object works on a new version. I intended to bytemove to copy my local array to the global one. I would have make sure that the underlying system checks a "busy" flag before it consults the map (or before I write a new map to it). The busy flag would be a kind of semaphore. I am aware of the fact that SPIN can do semaphores but I am not familiar enough with those yet to be able to use them yet. Maybe in the next version.
So, is this possible or will I need to just use an Object wide array for this purpose?
Gr,
Mightor
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
| Any sufficiently advanced technology is indistinguishable from magic.
Comments
Make sure the stack area for the cog is large enough for this array (and other local variables).
Post Edited (Mike Green) : 8/14/2007 6:19:17 PM GMT
Gr,
Mightor
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
| Any sufficiently advanced technology is indistinguishable from magic.
Oh ok, thanks. I am always messing those two operators up, the : and | [noparse]:)[/noparse] Still learning! Shame about the sequence subscripts not being legal, I guess that's what you get when you've been programming Python all day at work [noparse]:)[/noparse]
Gr,
Mightor
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
| Any sufficiently advanced technology is indistinguishable from magic.
(a) There is no such thing as "()"
(b) bazbaz is not a return value, use the "|"
(c) ".." is only valid with I/O register bit addressing
BTW: Why do you not want to use an array in the VAR section?
Mike,
Yeah, I thought of that and then realised that it might cause really weird behaviour if I ended up using a Prop2 controller some day with this new object of mine [noparse]:)[/noparse] I prefer to not touch things you're not supposed to, especially if I don't understand all the basic principles yet, maybe when I've become more comfortable with the Prop I'll venture into that territory.
Gr,
Mightor
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
| Any sufficiently advanced technology is indistinguishable from magic.
The re-entrant part hadn't occurred to me yet, probably because I would only really use a single cog to deal with my problem but I see what you mean. With two or more cogs you might need to do resource locking in some cases to prevent race conditions or conflicts. As for stack space, I have very little code atm, so I am going to give my cog copious amounts of stack space and narrow it down to what it really needs as my ability to judge that kind of thing gets better.
Maybe using OUTB isn't such a bad idea then, I'll consider it [noparse]:)[/noparse]
Gr,
Mightor
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
| Any sufficiently advanced technology is indistinguishable from magic.