Author: mturk Date: Sat Apr 25 17:12:14 2009 New Revision: 768566 URL: http://svn.apache.org/viewvc?rev=768566&view=rev Log: Pointer should be lightweight. Those will be part of Memory class
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer.java commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer32.java commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer64.java commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestMemory.java Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer.java URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer.java?rev=768566&r1=768565&r2=768566&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer.java (original) +++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer.java Sat Apr 25 17:12:14 2009 @@ -208,182 +208,6 @@ NullPointerException; /** - * Copy the memory area from {...@code this} pointer to array - * pointed by {...@code dst}. - * - * @param srcPos starting position in the source memory. - * @param dst destination {...@code array}. - * @param dstPos starting position in the destination array. - * @param length the number of bytes to be copied. - * - * @throws IllegalArgumentException if the {...@code srcPos} or - * {...@code dstPos} is {...@code negative} or {...@code length} - * is {...@code zero}. - * @throws IndexOutOfBoundsException if the operation would cause - * access of data outside allocated memory bounds. - * @throws NullPointerException if {...@code this} or {...@code dst} is - * {...@code null}. - */ - public abstract void copy(long srcPos, byte[] dst, - int dstPos, int length) - throws IndexOutOfBoundsException, IllegalArgumentException, - NullPointerException; - - /** - * Copy the memory area from {...@code this} pointer to array - * pointed by {...@code dst}. - * - * @param srcPos starting position in the source memory. - * @param dst destination {...@code array}. - * @param dstPos starting position in the destination array. - * @param length the number of bytes to be copied. - * - * @throws IllegalArgumentException if the {...@code srcPos} or - * {...@code dstPos} is {...@code negative} or {...@code length} - * is {...@code zero}. - * @throws IndexOutOfBoundsException if the operation would cause - * access of data outside allocated memory bounds. - * @throws NullPointerException if {...@code this} or {...@code dst} is - * {...@code null}. - */ - public abstract void copy(long srcPos, char[] dst, - int dstPos, int length) - throws IndexOutOfBoundsException, IllegalArgumentException, - NullPointerException; - - /** - * Copy the memory area from {...@code this} pointer to array - * pointed by {...@code dst}. - * - * @param srcPos starting position in the source memory. - * @param dst destination {...@code array}. - * @param dstPos starting position in the destination array. - * @param length the number of bytes to be copied. - * - * @throws IllegalArgumentException if the {...@code srcPos} or - * {...@code dstPos} is {...@code negative} or {...@code length} - * is {...@code zero}. - * @throws IndexOutOfBoundsException if the operation would cause - * access of data outside allocated memory bounds. - * @throws NullPointerException if {...@code this} or {...@code dst} is - * {...@code null}. - */ - public abstract void copy(long srcPos, int[] dst, - int dstPos, int length) - throws IndexOutOfBoundsException, IllegalArgumentException, - NullPointerException; - - /** - * Copy the memory area from {...@code this} pointer to array - * pointed by {...@code dst}. - * - * @param srcPos starting position in the source memory. - * @param dst destination {...@code array}. - * @param dstPos starting position in the destination array. - * @param length the number of bytes to be copied. - * - * @throws IllegalArgumentException if the {...@code srcPos} or - * {...@code dstPos} is {...@code negative} or {...@code length} - * is {...@code zero}. - * @throws IndexOutOfBoundsException if the operation would cause - * access of data outside allocated memory bounds. - * @throws NullPointerException if {...@code this} or {...@code dst} is - * {...@code null}. - */ - public abstract void copy(long srcPos, long[] dst, - int dstPos, int length) - throws IndexOutOfBoundsException, IllegalArgumentException, - NullPointerException; - - /** - * Copy the memory area to {...@code this} pointer from array - * pointed by {...@code dst}. - * - * @param src source {...@code array}. - * @param dstPos starting position in the source memory. - * @param srcPos starting position in the destination array. - * @param length the number of bytes to be copied. - * - * @throws IllegalArgumentException if the {...@code srcPos} or - * {...@code dstPos} is {...@code negative} or {...@code length} - * is {...@code zero}. - * @throws IndexOutOfBoundsException if the operation would cause - * access of data outside allocated memory bounds. - * @throws NullPointerException if {...@code this} or {...@code dst} is - * {...@code null}. - */ - public abstract void move(byte[] src, int srcPos, long dstPos, - int length) - throws IndexOutOfBoundsException, IllegalArgumentException, - NullPointerException; - - /** - * Copy the memory area to {...@code this} pointer from array - * pointed by {...@code dst}. - * - * @param src source {...@code array}. - * @param dstPos starting position in the source memory. - * @param srcPos starting position in the destination array. - * @param length the number of bytes to be copied. - * - * @throws IllegalArgumentException if the {...@code srcPos} or - * {...@code dstPos} is {...@code negative} or {...@code length} - * is {...@code zero}. - * @throws IndexOutOfBoundsException if the operation would cause - * access of data outside allocated memory bounds. - * @throws NullPointerException if {...@code this} or {...@code dst} is - * {...@code null}. - */ - public abstract void move(char[] src, int srcPos, - long dstPos, int length) - throws IndexOutOfBoundsException, IllegalArgumentException, - NullPointerException; - - /** - * Copy the memory area to {...@code this} pointer from array - * pointed by {...@code dst}. - * - * @param src source {...@code array}. - * @param dstPos starting position in the source memory. - * @param srcPos starting position in the destination array. - * @param length the number of bytes to be copied. - * - * @throws IllegalArgumentException if the {...@code srcPos} or - * {...@code dstPos} is {...@code negative} or {...@code length} - * is {...@code zero}. - * @throws IndexOutOfBoundsException if the operation would cause - * access of data outside allocated memory bounds. - * @throws NullPointerException if {...@code this} or {...@code dst} is - * {...@code null}. - */ - public abstract void move(int[] src, int srcPos, - long dstPos, int length) - throws IndexOutOfBoundsException, IllegalArgumentException, - NullPointerException; - - /** - * Copy the memory area to {...@code this} pointer from array - * pointed by {...@code dst}. - * - * @param src source {...@code array}. - * @param dstPos starting position in the source memory. - * @param srcPos starting position in the destination array. - * @param length the number of bytes to be copied. - * - * @throws IllegalArgumentException if the {...@code srcPos} or - * {...@code dstPos} is {...@code negative} or {...@code length} - * is {...@code zero}. - * @throws IndexOutOfBoundsException if the operation would cause - * access of data outside allocated memory bounds. - * @throws NullPointerException if {...@code this} or {...@code dst} is - * {...@code null}. - */ - public abstract void move(long[] src, int srcPos, - long dstPos, int length) - throws IndexOutOfBoundsException, IllegalArgumentException, - NullPointerException; - - /** * Copy the memory area from pointer {...@code src} to {...@code this} pointer. * <p> * Method uses the {...@code memmove} function to do a copying, meaning Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer32.java URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer32.java?rev=768566&r1=768565&r2=768566&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer32.java (original) +++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer32.java Sat Apr 25 17:12:14 2009 @@ -89,15 +89,7 @@ } private static native void copy0(int src, int dst, int length); - private static native void copy1(int addr, byte[] d, int dstPos, int len); - private static native void copy2(int addr, char[] d, int dstPos, int len); - private static native void copy3(int addr, int [] d, int dstPos, int len); - private static native void copy4(int addr, long[] d, int dstPos, int len); private static native void move0(int src, int dst, int length); - private static native void move1(int addr, byte[] d, int srcPos, int len); - private static native void move2(int addr, char[] d, int srcPos, int len); - private static native void move3(int addr, int [] d, int srcPos, int len); - private static native void move4(int addr, long[] d, int srcPos, int len); public void copy(long srcPos, Pointer dst, long dstPos, long length) @@ -116,73 +108,6 @@ copy0(POINTER + (int)srcPos, d32.POINTER + (int)dstPos, (int)length); } - public void copy(long srcPos, byte[] dst, - int dstPos, int length) - throws IndexOutOfBoundsException, IllegalArgumentException, - NullPointerException - { - if (POINTER == 0) - throw new NullPointerException(); - else if (srcPos < 0 || dstPos < 0 || length == 0) - throw new IllegalArgumentException(); - else if ((int)(srcPos + length) > PLENGTH) - throw new IndexOutOfBoundsException(); - else if ((dstPos + length) > dst.length) - throw new IndexOutOfBoundsException(); - copy1(POINTER + (int)srcPos, dst, dstPos, length); - } - - public void copy(long srcPos, char[] dst, - int dstPos, int length) - throws IndexOutOfBoundsException, IllegalArgumentException, - NullPointerException - { - long srcOff = srcPos * 2; - if (POINTER == 0) - throw new NullPointerException(); - else if (srcPos < 0L || dstPos < 0 || length == 0) - throw new IllegalArgumentException(); - else if ((int)(srcOff + (length * 2)) > PLENGTH) - throw new IndexOutOfBoundsException(); - else if ((dstPos + length) > dst.length) - throw new IndexOutOfBoundsException(); - copy2(POINTER + (int)srcOff, dst, dstPos, length); - } - - public void copy(long srcPos, int[] dst, - int dstPos, int length) - throws IndexOutOfBoundsException, IllegalArgumentException, - NullPointerException - { - long srcOff = srcPos * 4; - if (POINTER == 0) - throw new NullPointerException(); - else if (srcPos < 0L || dstPos < 0 || length == 0) - throw new IllegalArgumentException(); - else if ((int)(srcOff + (length * 4)) > PLENGTH) - throw new IndexOutOfBoundsException(); - else if ((dstPos + length) > dst.length) - throw new IndexOutOfBoundsException(); - copy3(POINTER + (int)srcOff, dst, dstPos, length); - } - - public void copy(long srcPos, long[] dst, - int dstPos, int length) - throws IndexOutOfBoundsException, IllegalArgumentException, - NullPointerException - { - long srcOff = srcPos * 8; - if (POINTER == 0) - throw new NullPointerException(); - else if (srcPos < 0L || dstPos < 0 || length == 0) - throw new IllegalArgumentException(); - else if ((int)(srcOff + (length * 8)) > PLENGTH) - throw new IndexOutOfBoundsException(); - else if ((dstPos + length) > dst.length) - throw new IndexOutOfBoundsException(); - copy4(POINTER + (int)srcOff, dst, dstPos, length); - } - public void move(Pointer src, long srcPos, long dstPos, long length) throws IndexOutOfBoundsException, IllegalArgumentException, @@ -200,73 +125,6 @@ move0(s32.POINTER + (int)dstPos, POINTER + (int)srcPos, (int)length); } - public void move(byte[] src, int srcPos, - long dstPos, int length) - throws IndexOutOfBoundsException, IllegalArgumentException, - NullPointerException - { - if (POINTER == 0) - throw new NullPointerException(); - else if (srcPos < 0 || dstPos < 0 || length == 0) - throw new IllegalArgumentException(); - else if ((int)(dstPos + length) > PLENGTH) - throw new IndexOutOfBoundsException(); - else if ((srcPos + length) > src.length) - throw new IndexOutOfBoundsException(); - move1(POINTER + (int)dstPos, src, srcPos, length); - } - - public void move(char[] src, int srcPos, - long dstPos, int length) - throws IndexOutOfBoundsException, IllegalArgumentException, - NullPointerException - { - long dstOff = dstPos * 2; - if (POINTER == 0) - throw new NullPointerException(); - else if (srcPos < 0 || dstPos < 0 || length == 0) - throw new IllegalArgumentException(); - else if ((int)(dstOff + (length * 2)) > PLENGTH) - throw new IndexOutOfBoundsException(); - else if ((srcPos + length) > src.length) - throw new IndexOutOfBoundsException(); - move2(POINTER + (int)dstOff, src, srcPos, length); - } - - public void move(int[] src, int srcPos, - long dstPos, int length) - throws IndexOutOfBoundsException, IllegalArgumentException, - NullPointerException - { - long dstOff = dstPos * 4; - if (POINTER == 0) - throw new NullPointerException(); - else if (srcPos < 0 || dstPos < 0 || length == 0) - throw new IllegalArgumentException(); - else if ((int)(dstOff + (length * 4)) > PLENGTH) - throw new IndexOutOfBoundsException(); - else if ((srcPos + length) > src.length) - throw new IndexOutOfBoundsException(); - move3(POINTER + (int)dstOff, src, srcPos, length); - } - - public void move(long[] src, int srcPos, - long dstPos, int length) - throws IndexOutOfBoundsException, IllegalArgumentException, - NullPointerException - { - long dstOff = dstPos * 8; - if (POINTER == 0) - throw new NullPointerException(); - else if (srcPos < 0 || dstPos < 0 || length == 0) - throw new IllegalArgumentException(); - else if ((int)(dstOff + (length * 8)) > PLENGTH) - throw new IndexOutOfBoundsException(); - else if ((srcPos + length) > src.length) - throw new IndexOutOfBoundsException(); - move4(POINTER + (int)dstOff, src, srcPos, length); - } - public String toString() { if (POINTER != 0) { Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer64.java URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer64.java?rev=768566&r1=768565&r2=768566&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer64.java (original) +++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer64.java Sat Apr 25 17:12:14 2009 @@ -89,15 +89,7 @@ } private static native void copy0(long src, long dst, long length); - private static native void copy1(long addr, byte[] d, int dstPos, int len); - private static native void copy2(long addr, char[] d, int dstPos, int len); - private static native void copy3(long addr, int [] d, int dstPos, int len); - private static native void copy4(long addr, long[] d, int dstPos, int len); private static native void move0(long src, long dst, long length); - private static native void move1(long addr, byte[] d, int srcPos, int len); - private static native void move2(long addr, char[] d, int srcPos, int len); - private static native void move3(long addr, int [] d, int srcPos, int len); - private static native void move4(long addr, long[] d, int srcPos, int len); public void copy(long srcPos, Pointer dst, long dstPos, long length) @@ -116,73 +108,6 @@ copy0(POINTER + srcPos, d64.POINTER + dstPos, length); } - public void copy(long srcPos, byte[] dst, - int dstPos, int length) - throws IndexOutOfBoundsException, IllegalArgumentException, - NullPointerException - { - if (POINTER == 0L) - throw new NullPointerException(); - else if (srcPos < 0L || dstPos < 0 || length == 0) - throw new IllegalArgumentException(); - else if ((srcPos + length) > PLENGTH) - throw new IndexOutOfBoundsException(); - else if ((dstPos + length) > dst.length) - throw new IndexOutOfBoundsException(); - copy1(POINTER + srcPos, dst, dstPos, length); - } - - public void copy(long srcPos, char[] dst, - int dstPos, int length) - throws IndexOutOfBoundsException, IllegalArgumentException, - NullPointerException - { - long srcOff = srcPos * 2; - if (POINTER == 0L) - throw new NullPointerException(); - else if (srcPos < 0L || dstPos < 0 || length == 0) - throw new IllegalArgumentException(); - else if ((srcOff + (length * 2)) > PLENGTH) - throw new IndexOutOfBoundsException(); - else if ((dstPos + length) > dst.length) - throw new IndexOutOfBoundsException(); - copy2(POINTER + srcOff, dst, dstPos, length); - } - - public void copy(long srcPos, int[] dst, - int dstPos, int length) - throws IndexOutOfBoundsException, IllegalArgumentException, - NullPointerException - { - long srcOff = srcPos * 4; - if (POINTER == 0L) - throw new NullPointerException(); - else if (srcPos < 0L || dstPos < 0 || length == 0) - throw new IllegalArgumentException(); - else if ((srcOff + (length * 4)) > PLENGTH) - throw new IndexOutOfBoundsException(); - else if ((dstPos + length) > dst.length) - throw new IndexOutOfBoundsException(); - copy3(POINTER + srcOff, dst, dstPos, length); - } - - public void copy(long srcPos, long[] dst, - int dstPos, int length) - throws IndexOutOfBoundsException, IllegalArgumentException, - NullPointerException - { - long srcOff = srcPos * 8; - if (POINTER == 0L) - throw new NullPointerException(); - else if (srcPos < 0L || dstPos < 0 || length == 0) - throw new IllegalArgumentException(); - else if ((srcOff + (length * 8)) > PLENGTH) - throw new IndexOutOfBoundsException(); - else if ((dstPos + length) > dst.length) - throw new IndexOutOfBoundsException(); - copy4(POINTER + srcOff, dst, dstPos, length); - } - public void move(Pointer src, long srcPos, long dstPos, long length) throws IndexOutOfBoundsException, IllegalArgumentException, @@ -200,73 +125,6 @@ move0(s64.POINTER + dstPos, POINTER + srcPos, length); } - public void move(byte[] src, int srcPos, - long dstPos, int length) - throws IndexOutOfBoundsException, IllegalArgumentException, - NullPointerException - { - if (POINTER == 0L) - throw new NullPointerException(); - else if (srcPos < 0 || dstPos < 0L || length == 0) - throw new IllegalArgumentException(); - else if ((dstPos + length) > PLENGTH) - throw new IndexOutOfBoundsException(); - else if ((srcPos + length) > src.length) - throw new IndexOutOfBoundsException(); - move1(POINTER + dstPos, src, srcPos, length); - } - - public void move(char[] src, int srcPos, - long dstPos, int length) - throws IndexOutOfBoundsException, IllegalArgumentException, - NullPointerException - { - long dstOff = dstPos * 2; - if (POINTER == 0) - throw new NullPointerException(); - else if (srcPos < 0 || dstPos < 0 || length == 0) - throw new IllegalArgumentException(); - else if ((dstOff + (length * 2)) > PLENGTH) - throw new IndexOutOfBoundsException(); - else if ((srcPos + length) > src.length) - throw new IndexOutOfBoundsException(); - move2(POINTER + dstOff, src, srcPos, length); - } - - public void move(int[] src, int srcPos, - long dstPos, int length) - throws IndexOutOfBoundsException, IllegalArgumentException, - NullPointerException - { - long dstOff = dstPos * 4; - if (POINTER == 0) - throw new NullPointerException(); - else if (srcPos < 0 || dstPos < 0 || length == 0) - throw new IllegalArgumentException(); - else if ((dstOff + (length * 4)) > PLENGTH) - throw new IndexOutOfBoundsException(); - else if ((srcPos + length) > src.length) - throw new IndexOutOfBoundsException(); - move3(POINTER + dstOff, src, srcPos, length); - } - - public void move(long[] src, int srcPos, - long dstPos, int length) - throws IndexOutOfBoundsException, IllegalArgumentException, - NullPointerException - { - long dstOff = dstPos * 8; - if (POINTER == 0) - throw new NullPointerException(); - else if (srcPos < 0 || dstPos < 0 || length == 0) - throw new IllegalArgumentException(); - else if ((dstOff + (length * 8)) > PLENGTH) - throw new IndexOutOfBoundsException(); - else if ((srcPos + length) > src.length) - throw new IndexOutOfBoundsException(); - move4(POINTER + dstOff, src, srcPos, length); - } - public String toString() { if (POINTER != 0L) { Modified: commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c?rev=768566&r1=768565&r2=768566&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c Sat Apr 25 17:12:14 2009 @@ -200,71 +200,6 @@ memmove(N2P(d, void *), N2P(s, const void *), (size_t)l); } -ACR_PTR_EXPORT_DECLARE(void, copy1)(ACR_JNISTDARGS, jniptr a, jbyteArray dst, - jint off, jint len) -{ - UNREFERENCED_O; - - (*_E)->SetByteArrayRegion(_E, dst, (jsize)off, (jsize)len, N2P(a, jbyte *)); -} - -ACR_PTR_EXPORT_DECLARE(void, copy2)(ACR_JNISTDARGS, jniptr a, jcharArray dst, - jint off, jint len) -{ - UNREFERENCED_O; - - (*_E)->SetCharArrayRegion(_E, dst, (jsize)off, (jsize)len, N2P(a, jchar *)); -} - -ACR_PTR_EXPORT_DECLARE(void, copy3)(ACR_JNISTDARGS, jniptr a, jintArray dst, - jint off, jint len) -{ - UNREFERENCED_O; - - (*_E)->SetIntArrayRegion(_E, dst, (jsize)off, (jsize)len, N2P(a, jint *)); -} - -ACR_PTR_EXPORT_DECLARE(void, copy4)(ACR_JNISTDARGS, jniptr a, jlongArray dst, - jint off, jint len) -{ - UNREFERENCED_O; - - (*_E)->SetLongArrayRegion(_E, dst, (jsize)off, (jsize)len, N2P(a, jlong *)); -} - -ACR_PTR_EXPORT_DECLARE(void, move1)(ACR_JNISTDARGS, jniptr a, jbyteArray src, - jint off, jint len) -{ - UNREFERENCED_O; - - (*_E)->GetByteArrayRegion(_E, src, (jsize)off, (jsize)len, N2P(a, jbyte *)); -} - -ACR_PTR_EXPORT_DECLARE(void, move2)(ACR_JNISTDARGS, jniptr a, jcharArray src, - jint off, jint len) -{ - UNREFERENCED_O; - - (*_E)->GetCharArrayRegion(_E, src, (jsize)off, (jsize)len, N2P(a, jchar *)); -} - -ACR_PTR_EXPORT_DECLARE(void, move3)(ACR_JNISTDARGS, jniptr a, jintArray src, - jint off, jint len) -{ - UNREFERENCED_O; - - (*_E)->GetIntArrayRegion(_E, src, (jsize)off, (jsize)len, N2P(a, jint *)); -} - -ACR_PTR_EXPORT_DECLARE(void, move4)(ACR_JNISTDARGS, jniptr a, jlongArray src, - jint off, jint len) -{ - UNREFERENCED_O; - - (*_E)->GetLongArrayRegion(_E, src, (jsize)off, (jsize)len, N2P(a, jlong *)); -} - - ACR_DECLARE(jobject) ACR_PointerCreate(JNIEnv *_E, void *p, size_t len, acr_pointer_cleanup_fn_t *cb) { Modified: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestMemory.java URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestMemory.java?rev=768566&r1=768565&r2=768566&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestMemory.java (original) +++ commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestMemory.java Sat Apr 25 17:12:14 2009 @@ -246,123 +246,6 @@ p.free(); } - public void testCopyToArray() - { - Pointer p = Memory.calloc(1000); - assertNotNull("Pointer", p); - Memory.set(p, 0, 1000, 0xFF); - p.poke(0, 23); - byte [] b = new byte[32]; - - p.copy(0, b, 0, b.length); - assertEquals("Value", 23, b[0]); - assertEquals("Value", (byte)0xFF, b[1]); - - } - - public void testCopyToCharArray() - { - Pointer p = Memory.calloc(1000); - assertNotNull("Pointer", p); - Memory.set(p, 0, 1000, 0xFF); - p.poke(0, 0x11); - p.poke(1, 0x11); - char [] c = new char[32]; - - p.copy(0, c, 0, c.length); - assertEquals("Value", 0x1111, c[0]); - assertEquals("Value", (char)0xFFFF, c[1]); - - } - - public void testCopyToIntArray() - { - Pointer p = Memory.calloc(1000); - assertNotNull("Pointer", p); - Memory.set(p, 0, 1000, 0xFF); - for (int j = 0; j < 4; j++) - p.poke(j, 0x11); - int [] i = new int[32]; - - p.copy(0, i, 0, i.length); - assertEquals("Value", 0x11111111, i[0]); - assertEquals("Value", 0xFFFFFFFF, i[1]); - - } - - public void testCopyToLongArray() - { - Pointer p = Memory.calloc(1000); - assertNotNull("Pointer", p); - Memory.set(p, 0, 1000, 0xFF); - for (int j = 0; j < 8; j++) - p.poke(j, 0x11); - long [] l = new long[32]; - - p.copy(0, l, 0, l.length); - assertEquals("Value", 0x1111111111111111L, l[0]); - assertEquals("Value", 0xFFFFFFFFFFFFFFFFL, l[1]); - - } - - public void testCopyFromArray() - { - Pointer p = Memory.calloc(1000); - assertNotNull("Pointer", p); - Memory.set(p, 0, 1000, 0xFF); - p.poke(0, 23); - byte [] b = new byte[32]; - - p.move(b, 0, 1, b.length); - assertEquals("Value", 23, p.peek(0)); - assertEquals("Value", 0, p.peek(1)); - - } - - public void testCopyFromCharArray() - { - Pointer p = Memory.calloc(1000); - assertNotNull("Pointer", p); - Memory.set(p, 0, 1000, 0xFF); - p.poke(0, 23); - char [] c = new char[32]; - - p.move(c, 0, 1, c.length); - assertEquals("Value", 23, p.peek(0)); - assertEquals("Value", -1, p.peek(1)); - assertEquals("Value", 0, p.peek(2)); - - } - - public void testCopyFromIntArray() - { - Pointer p = Memory.calloc(1000); - assertNotNull("Pointer", p); - Memory.set(p, 0, 1000, 0xFF); - p.poke(0, 23); - int [] i = new int[32]; - - p.move(i, 0, 1, i.length); - assertEquals("Value", 23, p.peek(0)); - assertEquals("Value", -1, p.peek(3)); - assertEquals("Value", 0, p.peek(4)); - - } - - public void testCopyFromLongArray() - { - Pointer p = Memory.calloc(1000); - assertNotNull("Pointer", p); - Memory.set(p, 0, 1000, 0xFF); - p.poke(0, 23); - long [] l = new long[32]; - - p.move(l, 0, 1, l.length); - assertEquals("Value", 23, p.peek(0)); - assertEquals("Value", -1, p.peek(7)); - assertEquals("Value", 0, p.peek(8)); - - } }