2004年08月10日 星期二 08:05
比如: a=[1,2,3] 测试 a 在内存中的所占的字节数
2004年08月10日 星期二 11:05
import struct
struct.pack
struct.calcsize ?
难道使用这个方法吗?
我也想知道有什么方法来计算对象的size
*calcsize*( fmt)
Return the size of the struct (and hence of the string)
corresponding to the given format.
Format characters have the following meaning; the conversion between C
and Python values should be obvious given their types:
*Format* *C Type* *Python* *Notes*
x pad byte no value
c char string of length 1
b signed char integer
B unsigned char integer
h short integer
H unsigned short integer
i int integer
I unsigned int long
l long integer
L unsigned long long
q long long long (1)
Q unsigned long long long (1)
f float float
d double float
s char[] string
p char[] string
P void * integer
tocer wrote:
>比如:
>a=[1,2,3]
>测试 a 在内存中的所占的字节数
>
>------------------------------------------------------------------------
>
>_______________________________________________
>python-chinese list
>python-chinese at lists.python.cn
>http://python.cn/mailman/listinfo/python-chinese
>
>
2004年08月10日 星期二 11:57
这个不行,只能用来计算struct模块生成的c struct的大小。 计算Python对象占用空间的模块不知道有没有人写了。如果没人写的话,应该是一个新的项目的好题材 :) ----- Original Message ----- From: "gentoo.cn" <gentoo.cn at 126.com> To: <python-chinese at lists.python.cn> Sent: Tuesday, August 10, 2004 11:05 AM Subject: Re: [python-chinese] 如何测量一个变量或者常量在内存中的大小 > import struct > struct.pack > struct.calcsize ? > > 难道使用这个方法吗? > 我也想知道有什么方法来计算对象的size > > *calcsize*( fmt) > > Return the size of the struct (and hence of the string) > corresponding to the given format. > > Format characters have the following meaning; the conversion between C > and Python values should be obvious given their types: > > *Format* *C Type* *Python* *Notes* > x pad byte no value > c char string of length 1 > b signed char integer > B unsigned char integer > h short integer > H unsigned short integer > i int integer > I unsigned int long > l long integer > L unsigned long long > q long long long (1) > Q unsigned long long long (1) > f float float > d double float > s char[] string > p char[] string > P void * integer > > > tocer wrote: > > >比如: > >a=[1,2,3] > >测试 a 在内存中的所占的字节数 > > > >------------------------------------------------------------------------ > > > >_______________________________________________ > >python-chinese list > >python-chinese at lists.python.cn > >http://python.cn/mailman/listinfo/python-chinese > > > > > > _______________________________________________ > python-chinese list > python-chinese at lists.python.cn > http://python.cn/mailman/listinfo/python-chinese > >
2004年08月10日 星期二 12:08
On 2004-08-10 11:57:1092110222 +0800, Jacob Fan wrote: > 这个不行,只能用来计算struct模块生成的c struct的大小。 > 计算Python对象占用空间的模块不知道有没有人写了。如果没人写的话,应该是一个新的项目的好题材 :) 记得 python 中有一个查看占用内存的函数,在建立新对象前后分别运行一下, 就可以看到新对象占用了多少空间。不过我忘记这是那个函数了。
Zeuux © 2025
京ICP备05028076号