13 messages in net.java.dev.jna.usersRe: [jna-users] array of pointers of ...
FromSent OnAttachments
Zsolt KútiMay 11, 2009 12:18 pm 
Timothy WallMay 11, 2009 12:22 pm 
Zsolt KútiMay 11, 2009 12:46 pm 
Timothy WallMay 11, 2009 1:06 pm 
Zsolt KútiMay 14, 2009 1:30 pm 
Timothy WallMay 14, 2009 1:58 pm 
Zsolt KútiMay 16, 2009 12:19 pm 
Timothy WallMay 16, 2009 6:42 pm 
Zsolt KútiMay 17, 2009 10:32 am 
Timothy WallMay 17, 2009 10:41 am 
Zsolt KútiMay 17, 2009 11:08 am 
Timothy WallMay 17, 2009 12:47 pm 
Zsolt KútiMay 18, 2009 10:33 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: [jna-users] array of pointers of a structActions...
From:Zsolt Kúti (kut@t-online.hu)
Date:May 18, 2009 10:33:45 am
List:net.java.dev.jna.users

On Sun, 17 May 2009 15:47:26 -0400 Timothy Wall <twal@dev.java.net> wrote:

On May 17, 2009, at 2:09 PM, Zsolt Kúti wrote:

On Sun, 17 May 2009 13:41:59 -0400 Timothy Wall <twal@dev.java.net> wrote:

On May 17, 2009, at 1:33 PM, Zsolt Kúti wrote:

The counterpart of an array of pointers what I need, I just uncertain how to approach that. The API doc says on Structure: When used as a function parameter or return value, this class corresponds to struct*. So I tried passing a variable of my Structure and using its toArray() method with the size that was given back via an IntByReference by the function. This does not seem to work either.

Just to be clear here is the defining C code: struct my_struct int f(struct my_struct *s, int *i)

In usage it looks: static struct my_struct my_s static unsigned int my_i (call) f(&my_s, &my_i) (use) my_s[0]

How does the native code know how many structures it can fill in? Presumably the "int *" will be filled in with the number of elements available, but you need that number before you call the function.

I guess this must be a usual idom in C for a dynamic array. The function uses the passed address to struct to start filling it and keep incrementing address while there are new data, counting them in a counter (my_i in this case).

Structure and Structure[] will pass the same address to the native code; the latter will point to a larger block of memory if the array size is greater than one.

What exactly isn't working?

There is no data in the struct, while my_i shows there must be one struct filled. The C code does work (as shown by a program that uses the same function).

Use a single Structure object, the same as you do in your C code. After the function call, JNA automatically calls Structure.read to populate the Java data, unless you tell it not to.

void f(MyStructure s, IntByReference iref);

You're saying when you pass in a Structure object this way, the native memory remains unchanged after the function call?

Yes, it is seemingly unchanged, the memory dump shows mere zeros.

Unless you have better idea, I would write a little C code with a struct and function that repeats this dynamic array usage and test its behavior.

Thanks!

Zsolt