问题-初始化big_list时,sys.getsizeof和pympler报告相同的内存(64字节)。我对此很好。循环按预期运行5次。但是每次循环时,为什么sys.getsizeof和asizeof向我显示不同的值,为什么这些值不相同?
这是python3的代码
import sys
from pympler.asizeof import asizeof
big_range = range(5)
big_List = []
print("big_list is of {} bytes when it is initalized".format(sys.getsizeof(big_List)))
print("memory report by pympler is {} bytes".format(str(asizeof(big_List))))
print("_________________________________________________________________")
for val in big_range:
big_List.append(val)
print("big_list is of {} bytes when it is appended ".format(sys.getsizeof(big_List)))
print("memory report by pympler is {} bytes".format(str(asizeof(big_List))))
print("_________________________________________________________________")
此处输出:
big_list is of 64 bytes when it is initalized
memory report by pympler is 64 bytes
_________________________________________________________________
big_list is of 96 bytes when it is appended
memory report by pympler is 120 bytes
_________________________________________________________________
big_list is of 96 bytes when it is appended
memory report by pympler is 152 bytes
_________________________________________________________________
big_list is of 96 bytes when it is appended
memory report by pympler is 184 bytes
_________________________________________________________________
big_list is of 96 bytes when it is appended
memory report by pympler is 216 bytes
_________________________________________________________________
big_list is of 128 bytes when it is appended
memory report by pympler is 280 bytes
_________________________________________________________________