If you're receiving an array of structures, you need a
PointerByReference. Use getValue() to get the Pointer, which you
then use in the call to setMemory on a single instance of your
Structure. You then use Structure.toArray() to get the full array,
which should auto-initialize all the structs from the memory you give
it.
Don't forget to free the pointer returned when you're done with it.
You're trying to read the returned memory as an array of pointers
rather than an array of structures.
On Jun 20, 2007, at 9:31 PM, Simon BASLE wrote:
Hi
Once again it seems that I'm unable to correctly understand the
examples
on javadoc overview...
I have a function that expects three parameters : an input int
code, an
int by reference which will receive the number of tasks running and an
array of struct pvmtaskinfo by reference, which will receive an
array of
structures pvmtaskinfo, one for each running task in the system...
I've mapped the int by reference to an IntByReference (so far so
good :p)
and I've tried mapping the last parameter to pvmtaskinfo,
pvmtaskinfo[]
and PointerByReference but no matter what I do I don't manage to
get it
work.
I've overriden useMemory which was protected => just a call to
super.useMemory(Pointer)... Also I have an no-arg constructor for
pvmtaskinfo.
Here is my current code (with the PointerByReference version) :
========================================
PointerByReference ptr = new PointerByReference();
IntByReference nbTasks = new IntByReference();
test.pvm_tasks(0, nbTasks, ptr);
Pointer[] allPtr = ptr.getValue().getPointerArray(0,
nbTasks.getValue());
for(int i = 0 ; i < allPtr.length ; i++)
{
if (allPtr[i] != null){
pvmtaskinfo toto = new pvmtaskinfo();
toto.useMemory(allPtr[i]);
toto.read();
//System.out.println(toto.ti_tid);
}
}
=======================================
Any clever idea? Need an expert point of view :p
Thanks
Simon