Pointers/References in Python?

Brian Blais bblais at bryant.edu
Wed Jul 30 11:12:37 EDT 2008


On Jul 30, 2008, at 10:46 , boblatest at googlemail.com wrote:

> Of course I can just build those lists naively by creating copies of
> the original list and then sorting them according to my wishes. But
> that would create huge memory overhead.

If the list itself is not memory intensive, but only the objects,  
then you shouldn't have to worry.  For example,

In [1]:big_object=[0.0]*int(1e7)  # about 40 meg

In [2]:big_object2=[0.0]*int(1e7) # another 40 meg

In [3]:list1=[big_object,big_object2]  # maybe a few bytes more, but  
no copy

In [4]:list2=[big_object2,big_object]  # maybe a few bytes more, but  
no copy


after this, my python process takes about 80 meg.  names like  
big_object are just names, and they reference an object in memory.   
if you say a=big_object, you are saying that the name "a" should also  
reference that same object.



			bb




-- 
Brian Blais
bblais at bryant.edu
http://web.bryant.edu/~bblais



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080730/98db6400/attachment-0001.html>


More information about the Python-list mailing list