Shop OBEX P1 Docs P2 Docs Learn Events
Proper way to call a method used by object further down the chain — Parallax Forums

Proper way to call a method used by object further down the chain

LarryGLarryG Posts: 50
edited 2010-04-24 15:02 in Propeller 1
Help a brother out, donate a cog [noparse]:)[/noparse]

I am running tight on cogs, and would really like to keep to one Prop chip for my bike computer if at all possible.

Master.spin is my main code, I assume runs in cog0
Fred is declared as an obj in Master.spin
Fred declares George as an object
Pub A in Master calls Fred.start
Fred.start starts George in his own cog (George has some heavy stuff and needs his own cog)

Pub B is some other method in Master.spin

Questions:
1) Can Pub B make use of methods in George?
2) If so, what is the proper syntax?
2) If not, do I need declare George as an object in Master.spin call him separately, and take up another cog?

Thanks for any suggestions.

-Larry G

Comments

  • ElectricAyeElectricAye Posts: 4,561
    edited 2010-04-24 14:21
    One trick I've heard of people using when they get tight with cogs is to stop cogs that they are no longer using. For example, if you are using FloatMath, you can start FloatMath in a cog, perform the calculations, then immediately stop that cog so it can be used for the next Method, etc.


    About cogstop, look what Mike Green says about it here:
    http://forums.parallax.com/showthread.php?p=872463

    Also see page 83 of the Propeller Manual.

    I hope that helps a bit.
  • localrogerlocalroger Posts: 3,452
    edited 2010-04-24 14:43
    Short answer: No, Pub B cannot make use of methods in George. There is no standard way to do that and it is a huge PITA in some situations such as when George is emitting debug clues.

    Long answer: If George does not make use of VAR data but only DAT, then all instances of George share data. This means you start George once but you can then include it in the OBJ fields of any and all modules and George's methods will then be available to all. If George has a start() method it should only be called by one of its followers, but then all can use its methods.
  • LarryGLarryG Posts: 50
    edited 2010-04-24 15:02
    OK, got it. Thanks @localroger and @ElectricAye. Both good advice, I appreciate the replies.
Sign In or Register to comment.