I want to know how to get size of objects like a string, integer, etc. in Python.
Related question: How many bytes per element are there in a Python list (tuple)?
Python 3.8 (Q1 2019) will change some of the results of sys.getsizeof, as announced here by Raymond Hettinger:
Python containers are 8 bytes smaller on 64-bit builds.
tuple () 48 -> 40
list [] 64 ->56
set() 224 -> 216
dict {} 240 -> 232
This comes after issue 33597 and Inada Naoki (methane)'s work around Compact PyGC_Head, and PR 7043
This idea reduces PyGC_Head size to two words.
Currently, PyGC_Head takes three words;
gc_prev,gc_next, andgc_refcnt.
gc_refcntis used when collecting, for trial deletion.gc_previs used for tracking and untracking.So if we can avoid tracking/untracking while trial deletion,
gc_prevandgc_refcntcan share same memory space.
See commit d5c875b:
Removed one
Py_ssize_tmember fromPyGC_Head.
All GC tracked objects (e.g. tuple, list, dict) size is reduced 4 or 8 bytes.