Shop OBEX P1 Docs P2 Docs Learn Events
Newbie Spin question re OBJ overhead — Parallax Forums

Newbie Spin question re OBJ overhead

cwegercweger Posts: 4
edited 2011-02-03 13:11 in Propeller 1
Hi,
I received my Propeller last week, so I'm pretty new to this stuff; apologies if this is a dumb question.

Does each "OBJ" declaration in Spin programs have much impact in the generated runtime? Is there an advantage to bundling objects together (i.e. is there significant per-object overhead at runtime)?

If I wanted to use, say, 20 smaller single-purpose objects rather than 3 or 4 more comprehensive ones, would that cause runtime code bloat? Or would that only result in editor/compiler overhead, without any runtime consequences?

Just trying to decide how to segment things for development & code management purposes.

Thanks!
-Chuck

Comments

  • Dave HeinDave Hein Posts: 6,347
    edited 2011-02-03 07:48
    Each object contains a table that is used for calling methods. The method table contains 4 bytes at the beginning that specify how large the object is, how many methods it has, and how many objects it references. It takes two bytes to call a method within an object vesus three byte if the method is outside of the object. So the overhead for using multiple object is pretty small.
  • Mike GreenMike Green Posts: 23,101
    edited 2011-02-03 07:49
    Each object has an entry point table that has a pointer (word) for each method plus a few other pointers. The OBJ declaration itself creates no "use dependent" overhead except that each reference to an object (OBJ) has it's own unique copy of any variables (VAR) used by the object.

    If you had 20 small single-purpose objects, each with a buffer of some sort (maybe 32 bytes), you'd need 20 * 32 bytes for variable storage. If you had only 3 or 4 more comprehensive objects, each with a 32 byte buffer that was shared by all the routines, you'd need 4 * 32 bytes for variable storage. Depending on the actual circumstances, there could be other solutions as well.
  • cwegercweger Posts: 4
    edited 2011-02-03 13:11
    Thanks guys, that's very helpful info.
    -Chuck
Sign In or Register to comment.