Python论坛  - 讨论区

标题:答复: Re: [python-chinese] 如何测量一个变量或者常量在内存中的大小

2004年08月10日 星期二 14:27

黎达文 ldw at suntektech.com
Tue Aug 10 14:27:19 HKT 2004

Python不需要自己分配内存,这就不需要有计算对象大小的说法啦!
 

-----邮件原件-----
发件人: python-chinese-bounces at lists.python.cn
[mailto:python-chinese-bounces at lists.python.cn] 代表 hoxide
发送时间: 2004年8月10日 12:59
收件人: gentoo.cn at 126.com, python-chines
主题: Re: Re: [python-chinese] 如何测量一个变量或者常量在内存中的大小

gentoo.cn,您好!

	资料不错,他的讨论证实了python中很难准确计算对象占用的内存数.
	其实现在我也对python的内存管理感兴趣,昨天发现mod_python好像存在内存
泄漏的问题.

======= 2004-08-10 12:53:49 您在来信中写道:=======

>找到一个相关的讨论
>http://www.egenix.com/mailman-archives/egenix-users/2002-November/00015
>6.html
>
>gentoo.cn wrote:
>
>>我的意思是:是不是可以通过计算一个Object的Struct来猜测这个Object的大小?
>>比如c='a', string="abcd"
>>那么c的类型是1c, string的类型是4c
>>calcsize('c')=1
>>calcsize('L')=4
>>也就是说一个数值型的对象占用4Bytes内存空间,一个字符型对象占用1Bytes内存
>>空间?
>>对于string="abcd"这个对象,类型是4c所以占用4Bytes内存空间?
>>不知道Python如何考虑对齐的(也许他最小的单位是1Bytes所以都是8bit的倍数,
>>这样就对齐了?)
>>
>>大家都来讨论讨论啊。
>>
>>
>>
>>limodou wrote:
>>
>>  
>>
>>>gentoo.cn,您好!
>>>
>>>	那个不是内存的大小吧。而是对应的struct的大小。因为在python中都是对
象,而不仅仅是数据结构。不知道:你想知道内存大小有什么用?
>>>
>>>======= 2004-08-10 11:05:42 您在来信中写道:=======
>>>
>>> 
>>>
>>>    
>>>
>>>>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
>>>>
>>>>   
>>>>
>>>>      
>>>>
>>>= = = = = = = = = = = = = = = = = = = =
>>>			
>>>
>>>        致
>>>礼!
>>>
>>>				 
>>>        limodou
>>>        chatme at 263.net
>>>          2004-08-10
>>>
>>> 
>>>
>>>---------------------------------------------------------------------
>>>---
>>>
>>>_______________________________________________
>>>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
>>
>>
>>  
>>
>
>_______________________________________________
>python-chinese list
>python-chinese at lists.python.cn
>http://python.cn/mailman/listinfo/python-chinese

= = = = = = = = = = = = = = = = = = = =
			

        致
礼!
 
				 
        hoxide
        hoxide_dirac at yahoo.com.cn
          2004-08-10


[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号