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/PointerBufferSE.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/PointerBufferSE.java')
-rwxr-xr-x | src/java/com/jogamp/common/nio/PointerBufferSE.java | 84 |
1 files changed, 0 insertions, 84 deletions
diff --git a/src/java/com/jogamp/common/nio/PointerBufferSE.java b/src/java/com/jogamp/common/nio/PointerBufferSE.java deleted file mode 100755 index f3fdc68..0000000 --- a/src/java/com/jogamp/common/nio/PointerBufferSE.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. - * Copyright (c) 2010 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - */ -package com.jogamp.common.nio; - -import com.jogamp.common.os.Platform; -import java.nio.*; - -/** - * @author Sven Gothel - * @author Michael Bien - */ -final class PointerBufferSE extends PointerBuffer { - - private Buffer pb; - - PointerBufferSE(ByteBuffer bb) { - super(bb); - - if (Platform.is32Bit()) { - this.pb = bb.asIntBuffer(); - } else { - this.pb = bb.asLongBuffer(); - } - } - - public final long get(int idx) { - if (0 > idx || idx >= capacity) { - throw new IndexOutOfBoundsException(); - } - if (Platform.is32Bit()) { - return (long) ((IntBuffer) pb).get(idx) & 0x00000000FFFFFFFFL; - } else { - return ((LongBuffer) pb).get(idx); - } - } - - public final PointerBufferSE put(int idx, long v) { - if (0 > idx || idx >= capacity) { - throw new IndexOutOfBoundsException(); - } - backup[idx] = v; - if (Platform.is32Bit()) { - ((IntBuffer) pb).put(idx, (int) v); - } else { - ((LongBuffer) pb).put(idx, v); - } - return this; - } - -} |