diff options
author | Sven Gothel <[email protected]> | 2011-04-27 19:47:43 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2011-04-27 19:47:43 +0200 |
commit | 8f8aa3f73e3c9804c4a86f5d4fdac257d50d831a (patch) | |
tree | 87497a9ffd60f4d3c2be2535312a72f84087a23d /src/java/com/jogamp/common/nio/NativeBuffer.java | |
parent | a07892f07f15c96ca248fc12133748be7058241f (diff) |
NativeBuffer/PointerBuffer API/Impl Change (remove explicit backup array, alloc referenced data map if used only)
This patch doesn't impact GlueGen's code generation,
but enhance and fix PointerBuffer usage only.
remove explicit backup array
As suggested by Michael Bien with a proposed patch,
PointerBuffer's backup array is not only redundant in case it's not used,
but also erroneous - due to possible sliced buffers.
Removes the explicit backup array implementation
leaving it up to the user, ie how PointerBuffer is created (alloc/allocDirect)
and use the underlying nio's buffer backup array, if available.
This also fixes the (never tested) case of indirect w/ backup array usage
on 32bit platform size. In this case the array shall be of type int[],
holding 32bit pointer - on 64bit long[].
Previous to this patch, it was always long[].
Added more thorough tests of PointerBuffer, notably indirect w/ backup array
and native deep copy and filling of a pointer array.
alloc referenced data map if used only
As suggested by Michael Bien with a proposed patch,
the allocation of the dataMap hash map is redundant in case it's not used.
The hash map will be initialized lazy, if needed only.
Diffstat (limited to 'src/java/com/jogamp/common/nio/NativeBuffer.java')
-rw-r--r-- | src/java/com/jogamp/common/nio/NativeBuffer.java | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/src/java/com/jogamp/common/nio/NativeBuffer.java b/src/java/com/jogamp/common/nio/NativeBuffer.java index ad6bb39..666907f 100644 --- a/src/java/com/jogamp/common/nio/NativeBuffer.java +++ b/src/java/com/jogamp/common/nio/NativeBuffer.java @@ -31,16 +31,19 @@ */ package com.jogamp.common.nio; +import java.nio.Buffer; import java.nio.ByteBuffer; /** * Hardware independent container for various kinds of buffers. * - * @author Michael Bien * @author Sven Gothel + * @author Michael Bien */ public interface NativeBuffer<B extends NativeBuffer> { + public int elementSize(); + public int limit(); public int capacity(); @@ -53,16 +56,30 @@ public interface NativeBuffer<B extends NativeBuffer> { public boolean hasRemaining(); + /** + * @return true if this buffer has a primitive backup array, otherwise false + */ public boolean hasArray(); + /** + * @return the array offset of the optional primitive backup array of the buffer if {@link #hasArray()} is true, + * otherwise 0. + */ public int arrayOffset(); - - public ByteBuffer getBuffer(); + + /** + * @return the primitive backup array of the buffer if {@link #hasArray()} is true, + * otherwise it throws {@link java.lang.UnsupportedOperationException}. + * The returned primitive array maybe of type <code>int[]</code> or <code>long[]</code>, etc .. + * @throws UnsupportedOperationException if this object has no backup array + * @see #hasArray() + */ + public Object array() throws UnsupportedOperationException ; + + public Buffer getBuffer(); public boolean isDirect(); - public long[] array(); - public B rewind(); public B put(int index, long value); @@ -74,5 +91,4 @@ public interface NativeBuffer<B extends NativeBuffer> { public long get(); public long get(int idx); - } |