http://www.perlmonks.org?node_id=974489


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.

Replies are listed 'Best First'.
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!!