public boolean allocateArrayBufferIfFirstTimeOrArrayChanged ( KernelArg arg , Object newRef , final int objArraySize , final int totalStructSize , final int totalBufferSize ) { boolean didReallocate = false ; if ( ( arg . getObjArrayBuffer ( ) == null ) || ( newRef != arg . getArray ( ) ) ) { final ByteBuffer structBuffer = ByteBuffer . allocate ( totalBufferSize ) ; arg . setObjArrayByteBuffer ( structBuffer . order ( ByteOrder . LITTLE_ENDIAN ) ) ; arg . setObjArrayBuffer ( arg . getObjArrayByteBuffer ( ) . array ( ) ) ; didReallocate = true ; if ( logger . isLoggable ( Level . FINEST ) ) { logger . finest ( "objArraySize = " + objArraySize + " totalStructSize= " + totalStructSize + " totalBufferSize=" + totalBufferSize ) ; } } else { arg . getObjArrayByteBuffer ( ) . clear ( ) ; } return didReallocate ; }
Helper method that manages the memory allocation for storing the kernel argument data so that the data can be exchanged between the host and the OpenCL device .