Shop OBEX P1 Docs P2 Docs Learn Events
Passing parameters to methods - Any way to pass more than 15? — Parallax Forums

Passing parameters to methods - Any way to pass more than 15?

ElectricAyeElectricAye Posts: 4,561
edited 2009-05-20 14:02 in Propeller 1
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
eyes.gif

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Watching the world pass me by, one photon at a time.

Comments

  • localrogerlocalroger Posts: 3,452
    edited 2009-05-20 01:01
    You could pass an array; that could be of any length, and the individual members are accessed with respect to their offset from the base, which you pass via @array.
  • BradCBradC Posts: 2,601
    edited 2009-05-20 01:18
    localroger said...
    You could pass an array; that could be of any length, and the individual members are accessed with respect to their offset from the base, which you pass via @array.

    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!
  • Mike HuseltonMike Huselton Posts: 746
    edited 2009-05-20 01:20
    I've used that method, localroger. I learned that trick from my AS400 days. The AS400 had a parameter passing area of memory called the Local Data Array (LDA). As a matter of fact, I cut my teeth on the AS400 and System 36/38. I still love the architecture of those machines. No buffer overruns or stack errors/memory faults were possible because the system memory had self-checking built-in at the hardware level.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    JMH

    Post Edited (James Michael Huselton) : 5/20/2009 1:31:42 AM GMT
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-05-20 01:26
    Just remember: when you pass an array address, you are effectively "passing by reference". This means that any changes you make to values in the array will be felt by the calling program. When you pass simple variables, you are "passing by value"; and, as with Las Vegas, "what happens in the method stays in the method" and does not affect those variables in the calling program.

    -Phil
  • ElectricAyeElectricAye Posts: 4,561
    edited 2009-05-20 01:36
    Hey guys,
    thanks a lot! This array technique sounds great.
    Phil Pilgrim (PhiPi) said...
    ...This means that any changes you make to values in the array will be felt by the calling program.....

    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

    smile.gifsmile.gifsmile.gifsmile.gifsmile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Watching the world pass me by, one photon at a time.
  • localrogerlocalroger Posts: 3,452
    edited 2009-05-20 12:57
    ElectricAye, you shouldn't have a problem with passing by reference since it's a display routine -- just make sure your display cog doesn't modify the values you pass it in the course of displaying them, and you'll be fine.
  • StefanL38StefanL38 Posts: 2,292
    edited 2009-05-20 13:40
    And even if you would like to modify them,

    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
  • ElectricAyeElectricAye Posts: 4,561
    edited 2009-05-20 14:02
    StefanL38 said...
    And even if you would like to modify them,

    you could copy them to a new array in the display-object
    and then do with the copied values what ever you like...

    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

    smile.gif

    Post Edited (ElectricAye) : 5/20/2009 4:03:41 PM GMT
Sign In or Register to comment.