Feel free to submit a patch for the portions of documentation that
need clarification.
On Jun 23, 2008, at 8:27 AM, RWAD...@UP.COM wrote:
I suspect you're probably right, though I haven't dug into the
details because I found a workaround. I finally got it to work when,
instead of creating new objects & storing their references in the
array, I just called the getters of the existingreferences in the
array.
This is obviously a place where the documentation needs major
expansion & clarification.
_______________________________
RWAD...@UP.COM wrote:
Point[] points = new Point[2];
points[0] = new Point(1,2);
points[1] = new Point(3,4);
Point[] structures = (Point[])new Point().toArray(points);
Not an expert, but I think you misunderstand this toArray call. The
javadoc:
public Structure[] toArray(Structure[] array)
Returns a view of this structure's memory as an array of structures.
Note that this Structure must have a public, no-arg constructor. If
the
structure is currently using a Memory backing, the memory will be
resized to fit the entire array.
I parse that as
(a) the first element of the returned array will be "this"
(b) subsequent elements of the returned array will be from "this"'s
memory
This fits your data:
(a) first point is Java allocated 0, 0
(b) second point is newly (C) allocated gibberish
The purpose would be to treat Structure* values passed from C as
Structure[] values when appropriate. The array param just reuses that
array, reduces that allocation.
One possible solution?
Point p = new Point(1, 2);
Point[] points = p.toArray(2);
p[1].setPoint(3, 4); // or some other assignment