Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Size of inside out object

by temporal (Pilgrim)
on Jun 05, 2012 at 16:01 UTC ( #974489=note: print w/ replies, xml ) Need Help??


in reply to Size of inside out object

IIRC, you'll actually come out slightly ahead (use less memory) if you end up instantiating more objects than you have attributes.

In a classic object model each object will contain a hash of attributes. For inside-out objects you have a hash per attribute regardless of the number of objects.

Strange things are afoot at the Circle-K.


Comment on Re: Size of inside out object
Re^2: Size of inside out object
by cheekuperl (Monk) on Jun 05, 2012 at 16:30 UTC
    Say I have an object "car" with attributes color and speed.
    Classical approach:
    Car A = hash A with keys color and speed
    Car B = hash B with keys color and speed

    Inside out approach:
    Car A = one hash for color, another for speed
    Car B = one hash for color, another for speed

    Which one will use less memory?

      For your given example, both will require two hashes, each with 2 of the 8 slots used. As near as make no difference, the memory usage will de identical for both.

      However, lets say you have 10 instances of a class that has 2 attributes:

      1. Classical: 10 hashes with 2 of 8 slots used ~ 80 hash slots + 20 scalars + 10 hash headers.
      2. Inside out: 2 hashes each with 10 of 16 slots used ~ 32 hash slots + 20 scalars + 2 hash headers.

      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      The start of some sanity?

        Thanks! I'll have to research more, but I got what I needed to know!!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://974489]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2014-12-28 23:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (183 votes), past polls