Login  Register

Re: GlueGen Struct Generator Update *API Change* .. etc

Posted by Sven Gothel on Jun 16, 2023; 12:33pm
URL: https://forum.jogamp.org/GlueGen-Struct-Generator-Update-API-Change-etc-tp4042685p4042690.html

Discussion-1: In cases where the memory is being replaced and the complete 'array' not being written due to 'destPos + length < elemCount', shouldn't the old content be copied into the new memory area?

See example below.

I would say yes ...

+++

Discussion-2: In 'const type*' cases where the memory is always being replaced even at 'destPos + length < elemCount', the elemCount can shrink. This is different than for 'type*' cases, where the setter never shrinks the elemCount.
Shall both variants behave the same, i.e. the 'const type*' case not shrink?

See example below.

I would say yes ...

Additionally, perhaps shall the setter contain a flag allowing the elemCount to be shrinked?
This also would help aligning the setter for both cases.

+++

See setter code for a 'const int32_t*', always replacing whole memory.
- Note: If destPos > 0, the new memory only has zero'ed bytes
- Note: elemCount shrinks if destPos + length < oldElemCount, contrary to non-const setter below

  /** Setter for native field <code>constInt32PointerVariaLen</code>: CType[(PointerType) 'int32_t *' -> (const int32_t) * , size [fixed false, lnx64 8], [const[false], pointer*1]], with initial array length of <code>0</code> */
  public final TK_Field setConstInt32PointerVariaLen(int[] src, final int srcPos, final int destPos, final int length) {
    if( 0 > srcPos || 0 > destPos || 0 > length || srcPos + length > src.length ) { throw new IndexOutOfBoundsException("src[pos "+srcPos+", length "+src.length+"], destPos "+destPos+", length "+length); }
    final int newElemCount = destPos + length;
    final ElementBuffer eb = ElementBuffer.allocateDirect(4, newElemCount);
    ( ( IntBuffer)(eb.getByteBuffer().asIntBuffer().position(destPos) ) ).put(src, srcPos, length).rewind();
    eb.storeDirectAddress(getBuffer(), constInt32PointerVariaLen_offset[mdIdx]);
    _ebConstInt32PointerVariaLen = eb;
    setConstInt32PointerVariaLenElemCount( newElemCount );
    return this;
  }
See setter code for a 'int32_t*', only replacing whole memory if 'destPos + length > elemCount'.
- Note: If destPos > 0 and destPos + length > elemCount, the new memory only has zero'ed bytes
- Note: elemCount never shrinks if destPos + length < oldElemCount, contrary to const setter above
- Note: To shrink the array, one would need to call 'releaseVariaInt32PointerVariaLen()'

  /** Setter for native field <code>variaInt32PointerVariaLen</code>: CType[(PointerType) 'int32_t *' -> (int32_t) * , size [fixed false, lnx64 8], [const[false], pointer*1]], with initial array length of <code>0</code> */
  public final TK_Field setVariaInt32PointerVariaLen(int[] src, final int srcPos, final int destPos, final int length) {
    if( 0 > srcPos || 0 > destPos || 0 > length || srcPos + length > src.length ) { throw new IndexOutOfBoundsException("src[pos "+srcPos+", length "+src.length+"], destPos "+destPos+", length "+length); }
    final int elemCount = getVariaInt32PointerVariaLenElemCount();
    if( destPos + length <= elemCount ) {
      final ElementBuffer eb = ElementBuffer.derefPointer(4, elemCount, getBuffer(), variaInt32PointerVariaLen_offset[mdIdx]);
      ( ( IntBuffer)(eb.getByteBuffer().asIntBuffer().position(destPos) ) ).put(src, srcPos, length).rewind();
    } else {
      final int newElemCount = destPos + length;
      final ElementBuffer eb = ElementBuffer.allocateDirect(4, newElemCount);
      ( ( IntBuffer)(eb.getByteBuffer().asIntBuffer().position(destPos) ) ).put(src, srcPos, length).rewind();
      eb.storeDirectAddress(getBuffer(), variaInt32PointerVariaLen_offset[mdIdx]);
      _ebVariaInt32PointerVariaLen = eb;
      setVariaInt32PointerVariaLenElemCount( newElemCount );
    }
    return this;
  }