Ai đó có thể giải thích cách sử dụng bộ nhớ không đơn điệu này của từ điển trong CPython 2.7?Mức tiêu thụ bộ nhớ không đơn điệu trong từ điển Python2
>>> import sys
>>> sys.getsizeof({})
280
>>> sys.getsizeof({'one': 1, 'two': 2, 'three': 3, 'four': 4, 'five': 5})
280
>>> sys.getsizeof({'one': 1, 'two': 2, 'three': 3, 'four': 4, 'five': 5, 'six': 6})
1048
>>> sys.getsizeof({'one': 1, 'two': 2, 'three': 3, 'four': 4, 'five': 5, 'six': 6, 'seven': 7})
1048
>>> sys.getsizeof({'one': 1, 'two': 2, 'three': 3, 'four': 4, 'five': 5, 'six': 6, 'seven': 7, 'e
ight': 8})
664
>>> sys.getsizeof({'one': 1, 'two': 2, 'three': 3, 'four': 4, 'five': 5, 'six': 6, 'seven': 7, 'e
ight': 8, 'nine': 9})
664
Python3 là hợp lý ở đây, nó in kích thước của {'one': 1, 'two': 2, 'three': 3, 'four': 4, 'five': 5, 'six': 6, 'seven': 7}
như 480.
Tôi cố gắng này trên Ubuntu 15.10 và OS X 10.11.
https://github.com/python/cpython/blob/2.7/Objects /dictobject.c –