data size
Michael Hudson
mwh at python.net
Fri Nov 9 06:56:11 EST 2001
"harry" <hartanto at telusplanet.net> writes:
> if you put data into dictionary, how do we calculate the data size?
Why do you want to know? It's not usually an interesting question to
ask in Python.
> key:data
>
> example:
>
> dict = {"key1":1,2,3,4; "key2": "hello", [1,2,3]}
> how much is the data structure will cost?
Err, lets see, a (small) dict is about 9*4 + 8*(3*4) = 124 bytes
the four character strings will be about 5*4 + 4 = 24 bytes
the list object will be about 30 bytes I think, similar for the tuple.
Small integers are preallocated and so cost nothing.
So the total for the above object is probably a couple of hundred
bytes.
I'm not sure how accurate the above is -- and I don't really care --
but it should give you an idea.
> how to calculate it?
Don't :) Memory is cheap.
Cheers,
M.
--
Never meddle in the affairs of NT. It is slow to boot and quick to
crash. -- Stephen Harris
-- http://home.xnet.com/~raven/Sysadmin/ASR.Quotes.html
More information about the Python-list
mailing list