Issue1543

classification
Title: PyArray fails to clean up pre-allocated space
Type: behaviour Severity: normal
Components: Core Versions: 2.5.1
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: zyasoft Nosy List: kwatford, pjenvey, zyasoft
Priority: high Keywords:

Created on 2010-01-14.19:04:59 by kwatford, last changed 2010-10-16.03:02:16 by zyasoft.

Messages
msg5438 (view) Author: Ken Watford (kwatford) Date: 2010-01-14.19:04:57
>>> from jarray import array
>>> from java.lang import Object
>>> x = array([0,1,2], Object)
>>> x.append(3)
>>> x
array(java.lang.Object, [0, 1, 2, 3])
>>> y = array([x], Object)
>>> y
array(java.lang.Object, [array(java.lang.Object, [0, 1, 2, 3, None, None, None])])
>>> x == y[0]
False

The append on x causes some extra array space to be allocated, but apparently the end of the array isn't remembered when assigned into y. However, if we use PyObject instead of Object...

>>> x = array([0,1,2], object)
>>> x.append(3)
>>> x
array(org.python.core.PyObject, [0, 1, 2, 3])
>>> y = array([x], object)
>>> y
array(org.python.core.PyObject, [array(org.python.core.PyObject, [0, 1, 2, 3])])
>>> x == y[0]
True

In case it matters:
$ java -version
java version "1.6.0_14"
Java(TM) SE Runtime Environment (build 1.6.0_14-b08)
Java HotSpot(TM) 64-Bit Server VM (build 14.0-b16, mixed mode)
msg5657 (view) Author: Philip Jenvey (pjenvey) Date: 2010-04-11.02:43:36
The problem here is the underlying array x does indeed get resized to a size of 7 when appended to, because the capacity increases of arrays always double the size of the array first (I'm not sure why, or if that's really desirable for the array type in the first place)

This is exposed in y because extending an array with an iterable apparently calls Py.tojava() on all the items of the iterable. That turns the x array into a real java array, then back to a Python array again, but without the precise size information it originally had
msg6171 (view) Author: Jim Baker (zyasoft) Date: 2010-10-16.03:02:15
Fixed in r7147
History
Date User Action Args
2010-10-16 03:02:16zyasoftsetstatus: open -> closed
resolution: fixed
messages: + msg6171
2010-09-09 05:45:10zyasoftsetpriority: high
2010-04-26 00:29:53zyasoftsetassignee: zyasoft
nosy: + zyasoft
2010-04-11 02:43:36pjenveysetnosy: + pjenvey
messages: + msg5657
2010-01-14 19:04:59kwatfordcreate