Could someone explain what happens with the memory behind the scenes when manipulating with dictionary and objects in the following example :
In [52]: class O(object):
....: var1 = 'asdfasdfasfasdfasdfasdfasdf'
....: var2 = 255
....:
In [53]: dt = {'var1': 'asdfasdfasfasdfasdfasdfasdf', 'var2': 255}
In [55]: o = O()
In [57]: sys.getsizeof(o)
Out[57]: 64
In [58]: sys.getsizeof(dt)
Out[58]: 280
Next thing is weird according to above values
In [68]: sys.getsizeof(o.var1)
Out[68]: 64
In [69]: sys.getsizeof(o.var2)
Out[69]: 24
In [70]: sys.getsizeof(dt['var1'])
Out[70]: 64
In [71]: sys.getsizeof(dt['var2'])
Out[71]: 24
The values in data structures are the same size, but the difference between types makes me wonder what happens on behind the scenes?
Does the example makes objects more effective over dictionaries?
I use Ubuntu 14.04 and Python 2.7.6