Passing parameters to methods - Any way to pass more than 15?
ElectricAye
Posts: 4,561
Hi all,
apparently I hit the 15 parameter limit on my use of a method (which is sent via a COGNEW to a new cog), so I was wondering if there's a nifty way to bypass that. My offending method is sent into a new cog that does nothing but display variables on a VGA so timing isn't a big deal; I just need to display the information to visually monitor a process. The variables are updated several times every second, so I thought about creating a "dummy parameter" that will pass a value every 0.1 second, and accompanying the "dummy parameter" will be a "code parameter" that will tell the cog/method exactly what value was being sent to it at that particular time.
In other words, if "code parameter" = 1, then the method knows that the value of "dummy parameter" at that particular moment pertains to Temperature 1 and displays it as such.
if "code parameter" = 2, then the method knows that the value of "dummy parameter" at that particular moment pertains to Temperature 2 and displays it as such.
And so forth and so on.
But this seems kinda clunky to me (and I'm not even sure if it will work yet). Might there be a more elegant way?
thanks,
Mark
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Watching the world pass me by, one photon at a time.
apparently I hit the 15 parameter limit on my use of a method (which is sent via a COGNEW to a new cog), so I was wondering if there's a nifty way to bypass that. My offending method is sent into a new cog that does nothing but display variables on a VGA so timing isn't a big deal; I just need to display the information to visually monitor a process. The variables are updated several times every second, so I thought about creating a "dummy parameter" that will pass a value every 0.1 second, and accompanying the "dummy parameter" will be a "code parameter" that will tell the cog/method exactly what value was being sent to it at that particular time.
In other words, if "code parameter" = 1, then the method knows that the value of "dummy parameter" at that particular moment pertains to Temperature 1 and displays it as such.
if "code parameter" = 2, then the method knows that the value of "dummy parameter" at that particular moment pertains to Temperature 2 and displays it as such.
And so forth and so on.
But this seems kinda clunky to me (and I'm not even sure if it will work yet). Might there be a more elegant way?
thanks,
Mark
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Watching the world pass me by, one photon at a time.
Comments
This is a much nicer way to do it. Remember any parameter you pass to a method is copied from the variable in question to the stack prior to the method being called. Passing an @array will only copy one value to the stack and allow you access to all the variables you require, while passing 15 variables has a massive time penalty of copying 15 variables to the stack prior to the call.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"VOOM"?!? Mate, this bird wouldn't "voom" if you put four million volts through it! 'E's bleedin' demised!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
JMH
Post Edited (James Michael Huselton) : 5/20/2009 1:31:42 AM GMT
-Phil
thanks a lot! This array technique sounds great.
But I'll have to think more about what PhiPi is saying and whether it has any implications to my application that might bite me in the end. At first glance, I'm feeling a little confused about that.
thanks so much!
Mark
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Watching the world pass me by, one photon at a time.
you could copy them to a new array in the display-object
and then do with the copied values what ever you like
best regards
Stefan
Yes, now I think I understand what PhiPi was saying about altering values inside memory address locations. The new Propeller Manual, version 1.1, talks a little about it on pages 184-185. Now I just need to find a good example/explanation of how to do the offsets properly when reading values out of the array.
For the record, a discussion on offset can be found on the forum at http://forums.parallax.com/showthread.php?p=809190
Thanks Stefan and localroger, you helped calm my fears of writing code that would burn me later.
cheers,
Mark
Post Edited (ElectricAye) : 5/20/2009 4:03:41 PM GMT