protected final <T extends Struct> T inner(T struct) { int off = align(__info.size, struct.__info.getMinimumAlignment()); struct.__info.enclosing = this; struct.__info.offset = off; __info.size = off + struct.__info.size; return struct; }
@SuppressWarnings("unchecked") public static <T extends Struct> T[] arrayOf(Runtime runtime, Class<T> type, int length) { try { T[] array = (T[]) Array.newInstance(type, length); Constructor<T> c = type.getConstructor(Runtime.class); for (int i = 0; i < length; ++i) { array[i] = c.newInstance(runtime); } if (array.length > 0) { final int structSize = align(Struct.size(array[0]), Struct.alignment(array[0])); jnr.ffi.Pointer memory = runtime.getMemoryManager().allocateDirect(structSize * length); for (int i = 0; i < array.length; ++i) { array[i].useMemory(memory.slice(structSize * i, structSize)); } } return array; } catch (RuntimeException ex) { throw ex; } catch (Exception ex) { throw new RuntimeException(ex); } }
@SuppressWarnings("unchecked") public static <T extends Struct> T[] arrayOf(Runtime runtime, Class<T> type, int length) { try { T[] array = (T[]) Array.newInstance(type, length); Constructor<T> c = type.getConstructor(Runtime.class); for (int i = 0; i < length; ++i) { array[i] = c.newInstance(runtime); } if (array.length > 0) { final int structSize = align(Struct.size(array[0]), Struct.alignment(array[0])); jnr.ffi.Pointer memory = runtime.getMemoryManager().allocateDirect(structSize * length); for (int i = 0; i < array.length; ++i) { array[i].useMemory(memory.slice(structSize * i, structSize)); } } return array; } catch (RuntimeException ex) { throw ex; } catch (Exception ex) { throw new RuntimeException(ex); } }
protected final <T extends Struct> T inner(T struct) { int off = align(__info.size, struct.__info.getMinimumAlignment()); struct.__info.enclosing = this; struct.__info.offset = off; __info.size = off + struct.__info.size; return struct; }
@SuppressWarnings("unchecked") public static <T extends Struct> T[] arrayOf(Runtime runtime, Class<T> type, int length) { try { T[] array = (T[]) Array.newInstance(type, length); Constructor<T> c = type.getConstructor(Runtime.class); for (int i = 0; i < length; ++i) { array[i] = c.newInstance(runtime); } if (array.length > 0) { final int structSize = align(Struct.size(array[0]), Struct.alignment(array[0])); jnr.ffi.Pointer memory = runtime.getMemoryManager().allocateDirect(structSize * length); for (int i = 0; i < array.length; ++i) { array[i].useMemory(memory.slice(structSize * i, structSize)); } } return array; } catch (RuntimeException ex) { throw ex; } catch (Exception ex) { throw new RuntimeException(ex); } }
protected final <T extends Struct> T inner(T struct) { int off = align(__info.size, struct.__info.getMinimumAlignment()); struct.__info.enclosing = this; struct.__info.offset = off; __info.size = off + struct.__info.size; return struct; }