

![]() | Start a set with this search |
![]() | Include this search in one of my sets |
![]() | Exclude this search from one of my sets |
![]() | Permalink to these results Paste this link in email or IM: |
| Atom feed for tracking future search results Paste this URL into your reader: |
4 messages in net.java.dev.jna.usersRe: [jna-users] Wrong Structure Value...| From | Sent On | Attachments |
|---|---|---|
| RWAD...@UP.COM | Jun 20, 2008 5:41 am | |
| Michael Brewer-Davis | Jun 20, 2008 10:59 am | |
| RWAD...@UP.COM | Jun 23, 2008 5:27 am | |
| Timothy Wall | Jun 23, 2008 11:52 am |

![]() | Permalink for this message Paste this link in email or IM: |
![]() | Permalink for this thread Paste this link in email or IM: |
| Atom feed for this thread Paste this URL into your reader: |
| Subject: | Re: [jna-users] Wrong Structure Values Passed | Actions... |
|---|---|---|
| From: | RWAD...@UP.COM (RWAD...@UP.COM) | |
| Date: | Jun 23, 2008 5:27:28 am | |
| List: | net.java.dev.jna.users | |
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 existing references in the array.
This is obviously a place where the documentation needs major expansion & clarification.
_______________________________
Hardware /nm./: the part of the computer you can kick.
Michael Brewer-Davis <mich...@tech4learning.com> 06/20/2008 12:58 PM Please respond to use...@jna.dev.java.net
To use...@jna.dev.java.net cc
Subject Re: [jna-users] Wrong Structure Values Passed
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
Maybe something more elegant.
michael
--------------------------------------------------------------------- To unsubscribe, e-mail: user...@jna.dev.java.net For additional commands, e-mail: user...@jna.dev.java.net
.
This message and any attachments contain information from Union Pacific which
may be confidential and/or privileged.
If you are not the intended recipient, be aware that any disclosure, copying,
distribution or use of the contents of this message is strictly prohibited by
law. If you receive this message in error, please contact the sender immediately
and delete the message and any attachments.







