If I were to add an isLeaf member function, I would have the cpu overhead of a function call every time I wanted to use that. I may switch it to 1/0, but doesn't that get rounded up to a 64-bit integer?
You have a simple space/time tradeoff to make, and you've indicated that the problem is space. If the overhead isn't significant for a slot in the object to hold a boolean to indicate whether the object is a leaf, then do it. But if you're still tight on space, trade that boolean for a function call. Sure, a function call takes "more CPU", but do you know whether that additional time is significant (or even measurable)? I'll bet that the overhead of
package Node;
sub isLeaf { 0 }
package Leaf;
isLeaf { 1 }
is barely measurable, and may be more than canceled out by not having to grow (at setup time) or access (at use time)the anonymous arrays that underly your objects.
| [reply] [d/l] |
This seems to have helped some, but I was thinking that I may be able to side step the more cpu vs more ram issue by using inline c.
However, I cannot seem to find a good ref for inline c, such as what happens to refs; or I could stop storing so much if my recursive calls ran fairly quickly, but when I pass my class to c++, does it keep the same methods, ect.
| [reply] |