[New-bugs-announce] [issue15424] __sizeof__ of array should include size of items

Ludwig Hähne report at bugs.python.org
Sun Jul 22 18:22:41 CEST 2012


New submission from Ludwig Hähne <wkx at 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 <report at bugs.python.org>
<http://bugs.python.org/issue15424>
_______________________________________


More information about the New-bugs-announce mailing list