in reply to Re: Size of inside out object
in thread Size of inside out object

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?

Replies are listed 'Best First'.
Re^3: Size of inside out object
by BrowserUk (Patriarch) on Jun 05, 2012 at 16:40 UTC

    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!!