Size of third-party object in memory
本问题已经有最佳答案,请猛点这里访问。
在
I型A 286mb文件使用实例代码(改性): </P >
1 2 3 4 | from Bio import SeqIO handle = open("example.gb","rU") records = list(SeqIO.parse(handle,"genbank")) handle.close() |
和
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | >>> l = [] >>> sys.getsizeof(l) 72 >>> zero = 0 >>> sys.getsizeof(zero) 24 >>> l.append(zero) >>> sys.getsizeof(l) 104 >>> 72 + 24 96 >>> l.append(zero) >>> sys.getsizeof(l) 104 >>> l.append(zero) >>> sys.getsizeof(l) 104 >>> l.append(zero) >>> sys.getsizeof(l) 104 >>> l.append(zero) >>> sys.getsizeof(l) 136 >>> >>> class Foo(object): ... def __init__(self, bar=None): ... self.bar = bar ... >>> f = Foo() >>> sys.getsizeof(f) 64 >>> f.bar = 1 >>> sys.getsizeof(f) 64 >>> f.bar = l >>> sys.getsizeof(f) 64 >>> |