Your skill will accomplish what the force of many cannot |
|
PerlMonks |
Re^4: Doubt about fly-weight objects.by etcshadow (Priest) |
on May 18, 2005 at 02:41 UTC ( [id://458052]=note: print w/replies, xml ) | Need Help?? |
<whacks self on side of head... rattling ensues>
I still don't get it. Let me make sure I understand what you are saying (please correct me where/if I got something screwed up): You're saying that you've got, let's say: a million instances of class Letter. The instance data of such a class is basically: a single character. Now, if you used non-fly-weight objects, you'd have each instance of the class be a reference to a scalar containing a character. So that's one million times a reference + one million times a character. Or, basically, one million times a platform-dependent, but small, number of bytes. Let's compare to fly-weights. With fly-weight-objects, you'd have one million times a reference to nothing (probably)... that is a scalar reference pointing to undef, I'd guess. Plus you'd have a hash mapping one million stringifications of a scalar reference to a character... so that hash contains one million characters, plus one million hash keys. That totals to one million times (a scalar reference + a character + a stringified scalar reference). That's considerably more than if you didn't use fly-weight objects (because a 20-odd character long string is pretty big compared to a scalar reference and a single character). If you'd chosen some sort of instance data that were actually larger (as opposed to a single character, which is about as small as you can get), then the difference between one reference and a reference plus a hash-key (stringification of that reference) would actually be inconsequential. Your example, though, actually makes fly-weights take up way more than twice as much space (I think). So, that's how I interpretted the situation you were laying out. I assume I just misintrpretted it... but how exactly did I?
In Section
Seekers of Perl Wisdom
|
|