New submission from Ludwig Hähne <w...@gmx.li>:

If sys.getsizeof is called on an array, the result doesn't include the size of 
the items: 

>>> from array import array
>>> a = array("i", [0] * 100000)
>>> a.__sizeof__()
40

While this makes sense for a list, an array doesn't have separate referents 
that could be sized:

>>> import gc
>>> gc.get_referents(a)
[]

The attached patch adds an implementation of the __sizeof__ method for arrays 
that includes the size of the buffer for the elements.

It would be great if the patch would be considered for one of the upcoming 
versions of Python.

Thanks, Ludwig

----------
components: Library (Lib)
files: array_sizeof.patch
keywords: patch
messages: 166147
nosy: Pankrat
priority: normal
severity: normal
status: open
title: __sizeof__ of array should include size of items
type: behavior
versions: Python 2.7, Python 3.3, Python 3.4
Added file: http://bugs.python.org/file26479/array_sizeof.patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue15424>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to