A question about swinging Tarzan parameters through a Jungle of Methods.
ElectricAye
Posts: 4,561
I'm having a problem passing parameters from method to method which is insanely illustrated by the following quasi-code:
So my question is this: Is there any way to avoid having a parameter Tarzan-swing its way from one method to another if I don't really need the parameter until "deep down" in the method calls? In my particular application, Tarzan happens to be the address of an array stored in Hub RAM. Any suggestions?
Cheetah thanks you,
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Watching the world pass me by, one photon at a time.
PUB Main {Call up the Jungle Method and pass the Tarzan Parameter...} Jungle(Tarzan) 'Tarzan being a Hub RAM address. PUB Jungle(TarzanSwings) 'Method in which Tarzan isn't yet needed. {Call up the Swamp Method and pass the TarzanSwings Parameter...} Swamp(TarzanSwings) PUB Swamp(TarzanSwingsAgain) 'Method in which Tarzan is still not yet needed. {Call up the Trees Method and pass the TarzanSwingsAgain Parameter...} Trees(TarzanSwingsAgain) PUB Trees(TarzanSwingsAgainAndAgain) 'Method in which Tarzan is still not yet needed. {Call up the HighPowerLines Method and pass the TarzanSwingsAgainAndAgain Parameter...} HighPowerLines(TarzanSwingsAgainAndAgain) PUB HighPowerLines(TarzanDiesOfElectrocution) {This is the only place in the program where I really need Tarzan and if he hasn't been electrocuted by now then he certainly has died of exhaustion.}
So my question is this: Is there any way to avoid having a parameter Tarzan-swing its way from one method to another if I don't really need the parameter until "deep down" in the method calls? In my particular application, Tarzan happens to be the address of an array stored in Hub RAM. Any suggestions?
Cheetah thanks you,
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Watching the world pass me by, one photon at a time.
Comments
This seems to obvious to be correct... but what about using a global variable instead?
If they are in different objects things get a bit more tricky.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.
PUB Jungle
...WORD[noparse][[/noparse]$7FFE] := @tarzan
PUB HighPowerLines
...tarzan := long[noparse]/noparse]word[noparse][[/noparse]$7FFE
This guarantees everyone can find it, but you have to be careful not to step on it if you use the technique more than once.
In another thread we talked about using unused COGs as additional RAM. This would work as well in this case if you have not enough free HUB-RAM to use the high-memory trick but you have some unused COGs.
The HIGH memory trick would be better to read, if you use constants to define the memory adress and use the constant in both places where you access it.
Post Edited (MagIO2) : 5/29/2009 1:21:48 PM GMT
localroger,
by "high memory location" are you talking about the Hub RAM or would this be an EEPROM location?
And, if I understand this right, what you're saying is that instead of passing an address by using a variable NAME (like Tarzan, TarzanSwings, etc.), I can instead use hexadecimal notation to assign it a known NUMERICAL address???
Thanks, guys, and I'm sorry if my question seems obviously stupid. Until now, I guess I never had to figure out what it means for variables to be "global", etc.
Mark
Thanks, roger. And thanks to heater and Philldapill, too. I think I'm beginning to grok this thing now. Maybe Tarzan can take a short cut from now on.