/** Attempt to allocate memory if sufficient information is available. * Returns whether the operation was successful. */ protected void allocateMemory() { allocateMemory(false); }
/** * Create a new Structure instance of the given type * @param type desired Structure type * @return the new instance * @throws IllegalArgumentException if the instantiation fails */ public static <T extends Structure> T newInstance(Class<T> type) throws IllegalArgumentException { T s = Klass.newInstance(type); if (s instanceof ByValue) { s.allocateMemory(); } return s; }
private void allocateMemory(boolean avoidFFIType) { allocateMemory(calculateSize(true, avoidFFIType)); }
/** Ensure this memory has its size and layout calculated and its memory allocated. @param avoidFFIType used when computing FFI type information to avoid recursion */ private void ensureAllocated(boolean avoidFFIType) { if (memory == null) { allocateMemory(avoidFFIType); } else if (size == CALCULATE_SIZE) { this.size = calculateSize(true, avoidFFIType); if (!(this.memory instanceof AutoAllocated)) { // Ensure we've set bounds on the shared memory used try { this.memory = this.memory.share(0, this.size); } catch(IndexOutOfBoundsException e) { throw new IllegalArgumentException("Structure exceeds provided memory bounds", e); } } } }
protected Structure(Pointer p, int alignType, TypeMapper mapper) { setAlignType(alignType); setStringEncoding(Native.getStringEncoding(getClass())); initializeTypeMapper(mapper); validateFields(); if (p != null) { useMemory(p, 0, true); } else { allocateMemory(CALCULATE_SIZE); } initializeFields(); }
public int size() { if (size == CALCULATE_SIZE) { // force allocation allocateMemory(); } return size; }
/** Attempt to allocate memory if sufficient information is available. * Returns whether the operation was successful. */ protected void allocateMemory() { allocateMemory(false); }
private void allocateMemory(boolean avoidFFIType) { allocateMemory(calculateSize(true, avoidFFIType)); }
/** Create a new Structure instance of the given type * @param type desired Structure type * @return the new instance * @throws IllegalArgumentException if the instantiation fails */ public static Structure newInstance(Class<?> type) throws IllegalArgumentException { try { Structure s = (Structure)type.newInstance(); if (s instanceof ByValue) { s.allocateMemory(); } return s; } catch(InstantiationException e) { String msg = "Can't instantiate " + type; throw new IllegalArgumentException(msg, e); } catch(IllegalAccessException e) { String msg = "Instantiation of " + type + " not allowed, is it public?"; throw new IllegalArgumentException(msg, e); } }
/** Ensure this memory has its size and layout calculated and its memory allocated. @param avoidFFIType used when computing FFI type information to avoid recursion */ private void ensureAllocated(boolean avoidFFIType) { if (memory == null) { allocateMemory(avoidFFIType); } else if (size == CALCULATE_SIZE) { this.size = calculateSize(true, avoidFFIType); if (!(this.memory instanceof AutoAllocated)) { // Ensure we've set bounds on the shared memory used try { this.memory = this.memory.share(0, this.size); } catch(IndexOutOfBoundsException e) { throw new IllegalArgumentException("Structure exceeds provided memory bounds", e); } } } }
protected Structure(Pointer p, int alignType, TypeMapper mapper) { setAlignType(alignType); setStringEncoding(Native.getStringEncoding(getClass())); initializeTypeMapper(mapper); validateFields(); if (p != null) { useMemory(p, 0, true); } else { allocateMemory(CALCULATE_SIZE); } initializeFields(); }