Shop OBEX P1 Docs P2 Docs Learn Events
Cog reuse for repeated object instances in different object layers? — Parallax Forums

Cog reuse for repeated object instances in different object layers?

JasonEJasonE Posts: 16
edited 2008-02-01 15:32 in Propeller 1
Hi, here's my question: (I hope I can explain what I'm thinking clearly)

· If I need to re-use an·object (floatmath) in my main application and in other·object subroutines, can I keep my cog use (for floatmath) down to 1 cog for that?·

For example say I have an application method called main that uses floatmath.· Let's also say that main calls another object I've written called Do_calculation that also invokes floatmath.· In this scenario two cogs for floatmath are running, one for the main method and one for the Do_calculation object.· However, I really don't need·2 cogs running floatmath as all calculations will be sequential for this particular application.

··Is there a way to pass the use of the floatmath object from main·into the lower Do_calculation object and minimize cog use?·

(I do realize I could manually start and stop the floatmath object in each method of the Do_calculation object and before and after floatmath operations in main, but that would be clumsy and awkward.)

-JasonE

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-02-01 15:08
    Take a look at the Dynamic Math Lib in the Object Exchange. This is a version of the math lib that is designed to be used from more than one cog (and object).

    There's no simple way to share the use of something like the floating point package among several objects. It's possible to write objects so they can be used this way by putting their shared variables in a DAT section rather than a VAR section, but then you can run into problems when you want multiple instances of the object. For example, there's a debug object that uses serial I/O. It has to be specifically written to work when included in multiple objects because it needs to provide only a single serial I/O channel.
  • JasonEJasonE Posts: 16
    edited 2008-02-01 15:32
    Mike,

    Thank you for the guidance. I guess what I was imagining and hoping for was some sort of global object declaration.

    A guy can dream, can't he? [noparse]:)[/noparse]
Sign In or Register to comment.