humble-video-noarch/src/main/java/io/humble/ferry/Buffer.java
public java.nio.ByteBuffer getByteBuffer(int offset, int length,
      java.util.concurrent.atomic.AtomicReference<JNIReference> referenceReturn)
  {
    java.nio.ByteBuffer retval = this.java_getByteBuffer(offset, length);
    if (retval != null)
    {
      // increment the ref count of this class to reflect the
      // byte buffer
      java.util.concurrent.atomic.AtomicLong refCount =
        this.getJavaRefCount();
      refCount.incrementAndGet();
      
      // and use the byte buffer as the reference to track
      JNIReference ref = JNIReference.createNonFerryReference(
          this,
          retval, swigCPtr, refCount);
      if (referenceReturn != null)
        referenceReturn.set(ref);
      
      // and tell Java this byte buffer is in native order
      retval.order(java.nio.ByteOrder.nativeOrder());
      retval.position(0);
      retval.mark();
      retval.limit(this.getBufferSize());
    }
    return retval;
  }
public java.nio.ByteBuffer getByteBuffer(int offset, int length,
      java.util.concurrent.atomic.AtomicReference<JNIReference> referenceReturn)
  {
    java.nio.ByteBuffer retval = this.java_getByteBuffer(offset, length);
    if (retval != null)
    {
      // increment the ref count of this class to reflect the
      // byte buffer
      java.util.concurrent.atomic.AtomicLong refCount =
        this.getJavaRefCount();
      refCount.incrementAndGet();
      
      // and use the byte buffer as the reference to track
      JNIReference ref = JNIReference.createNonFerryReference(
          this,
          retval, swigCPtr, refCount);
      if (referenceReturn != null)
        referenceReturn.set(ref);
      
      // and tell Java this byte buffer is in native order
      retval.order(java.nio.ByteOrder.nativeOrder());
      retval.position(0);
      retval.mark();
      retval.limit(this.getBufferSize());
    }
    return retval;
  }
public java . nio . ByteBuffer getByteBuffer ( int offset , int length , java . util . concurrent . atomic . AtomicReference < JNIReference > referenceReturn ) { java . nio . ByteBuffer retval = this . java_getByteBuffer ( offset , length ) ; if ( retval != null ) { // increment the ref count of this class to reflect the // byte buffer java . util . concurrent . atomic . AtomicLong refCount = this . getJavaRefCount ( ) ; refCount . incrementAndGet ( ) ; // and use the byte buffer as the reference to track JNIReference ref = JNIReference . createNonFerryReference ( this , retval , swigCPtr , refCount ) ; if ( referenceReturn != null ) referenceReturn . set ( ref ) ; // and tell Java this byte buffer is in native order retval . order ( java . nio . ByteOrder . nativeOrder ( ) ) ; retval . position ( 0 ) ; retval . mark ( ) ; retval . limit ( this . getBufferSize ( ) ) ; } return retval ; }
Returns up to length bytes, starting at offset in the underlying
buffer we're managing, and also passed back a {@link JNIReference}
that can optionally be used by the caller to free the underlying
native memory.

<p>

The buffer position, mark are initialized to zero and limit
is set to the maximum capacity of this buffer.  For some
Buffer contents, the actual usable data in this buffer will
be less that the limit.

</p>
<p>

If you use this method you are accessing the direct native
memory associated with this buffer.  That means changes you make
to this buffer are immediately reflected in the underlying
memory.

</p>
<p>

Once you call this method,
the underlying native memory allocated will not be released until
all references to the returned ByteBuffer are no longer reachable and
at least one call to {@link JNIMemoryManager#gc()} has been
performed.  You can force the memory to be collect earlier
by using the {@link JNIReference} value returned when you
call this method.
</p><p>
The {@link JNIMemoryManager#gc()} is called whenever
Humble Video tries to allocate new memory for any Humble interface,
so normally you don't need to care about this.  If for some
reason no other Humble object is ever allocated, every
Humble object has
a finalizer as well that will do the right thing.

</p>
<p>

You can also start up
a separate thread to do continuously do Ferry garabage
collections by calling
{@link JNIMemoryManager#startCollectionThread()}.  This thread
will only wake up when it has work to do, so the overhead
is very low.  We don't turn it on by default since in
99.999% of cases you don't need to worry about it.

</p>

@param offset The offset (in bytes) into the buffer managed by
this Buffer
@param length The requested length (in bytes) you want to access.
The buffer returned may actually be longer than length.
@param referenceReturn If non null, on exit
calling {@link java.util.concurrent.atomic.AtomicReference#get()}
on this value will return a {@link JNIReference} you can use
for explicitly de-allocating the underlying native store
of the {@link java.nio.ByteBuffer}.  Call
{@link JNIReference#delete()} to do that.  <strong>Warning:</strong>
if you do call {@link JNIReference#delete()} on the
value returned in this parameter, then the returned byte buffer
will be immediately invalid.
@return A java.nio.ByteBuffer that directly accesses
the native memory this Buffer manages, or null if
error.
Returns up to length bytes starting at offset in the underlying buffer we re managing and also passed back a { @link JNIReference } that can optionally be used by the caller to free the underlying native memory .