2 messages in net.java.dev.jna.usersRe: [jna-users] array in a Structure
FromSent OnAttachments
amina guermoucheSep 9, 2008 2:09 am 
Timothy WallSep 9, 2008 6:16 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 in a StructureActions...
From:Timothy Wall (twal@dev.java.net)
Date:Sep 9, 2008 6:16:04 am
List:net.java.dev.jna.users

On Sep 9, 2008, at 5:10 AM, amina guermouche wrote:

Hello, I have this structure in C:

struct cell_t { struct coord_z3_t id; /**< cell coordinates in the mesh */ unsigned int point[8]; /**< array of indexed points defined */ struct cell_list_t *neighbour_list[6]; /**< cell's neighbourhood */ struct cell_info_t *cell_info; /**< score information summary */

};

I've translated it in java this way: public class cell_t extends Structure{ public coord_z3_t id; public int point[]=new int[8]; public cell_list_t []neighbour_list[]; public cell_info_t cell_info[]; }

The last two fields (according to the C code) are an array of pointers and a single pointer, respectively.

public Pointer[] neighbour_list = new Pointer[6]; public Pointer cell_info;

Alternatively, if you actually need to dig into neighbor_list and cell_info:

public class cell_list_t extends Structure { public static class ByReference extends cell_list_t implements Structure.ByReference { } ... } public class cell_info_t extends Structure { public static class ByReference extends cell_info_t implements Structure.ByReference { } ... }

// then your fields look like this: public cell_list_t.ByReference[] neighbour_list = new cell_list_t.ByReference[6]; public cell_info_t.ByReference cell_info;

THe problem I have is that in C, all the fields of the structure are initialized later (especially the arrays), but in java, if I don't initialize the arrays, the program doesn't work because I have to initialize them. I don't know the size here, so I've just tried to put the size at 1, but that causes a stack overflow error.