Class CPointerMutable<T>
- java.lang.Object
-
- org.cakelab.blender.nio.CFacade
-
- org.cakelab.blender.nio.CPointer<T>
-
- org.cakelab.blender.nio.CPointerMutable<T>
-
- Type Parameters:
T
- target type of the pointer.
public class CPointerMutable<T> extends CPointer<T>
This class is the mutable variant ofCPointer
.Mutable pointers allow in-place modification of the pointers address and thereby advanced pointer arithmetics (better runtime performance). Please note, that modifications to the address will not be reflected in the memory region this pointer originated from.
You receive a mutable variant of a pointer either by using one of the copy constructors
CPointerMutable(CPointer)
orCPointerMutable(CPointer, long)
or by calling the methodCPointer.mutable()
.Pointer Arithmetics
Read documentation of
CPointer
first, to understand this section.CPointerMutable
inherits the methods ofCPointer
. Since references to objects ofCPointerMutable
can be assigned toCPointer
, the methodplus(int)
has to behave exactly likeCPointer.plus(int)
and return a new instance ofCPointerMutable
.The method
add(int)
now provides the functionality ofplus(int)
with in-place modification, meaning the address of the pointer object, on which the method was called, will be changed afterwards.Furthermore, mutable pointers support direct modification of their address by use of the methods
assign(long)
andassign(CPointer)
.- Author:
- homac
-
-
Field Summary
-
Fields inherited from class org.cakelab.blender.nio.CPointer
targetSize, targetTypeList
-
Fields inherited from class org.cakelab.blender.nio.CFacade
__io__address, __io__arch_index, __io__block, __io__blockTable, __io__pointersize
-
-
Constructor Summary
Constructors Constructor Description CPointerMutable(CPointer<T> pointer)
Constructor to turn a pointer into a mutable pointer.CPointerMutable(CPointer<T> pointer, long address)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CPointerMutable<T>
add(int increment)
void
assign(long address)
Equivalent tovoid
assign(CPointer<T> address)
Equivalent toCPointerMutable<T>
plus(int value)
long
value()
Returns the value of the address.-
Methods inherited from class org.cakelab.blender.nio.CPointer
__get, __set, cast, cast, cast, equals, fromArray, fromArray, fromArray, fromArray, fromArray, fromArray, fromArray, fromArray, fromArray, fromArray, fromArray, fromArray, fromInt64Array, fromInt64Array, get, getAddress, getCFacade, getScalar, isNull, isPrimitive, isValid, mutable, set, setScalar, toArray, toArray, toArray, toArray, toArray, toArray, toArray, toArrayInt64, toByteArray, toCArrayFacade, toDoubleArray, toFloatArray, toInt64Array, toIntArray, toLongArray, toShortArray
-
Methods inherited from class org.cakelab.blender.nio.CFacade
__io__addressof, __io__addressof, __io__equals, __io__generic__copy, __io__generic__copy, __io__instanceof, __io__native__copy, __io__newInstance, __io__same__encoding, __io__sizeof, __io__sizeof, __io__subclassof, hashCode
-
-
-
-
Method Detail
-
add
public CPointerMutable<T> add(int increment)
add(int)
is different toplus(int)
. Whileadd(int)
modifies the address in-placeplus(int)
returns a new instance with the result of the addition. Equivalent toint* p; (p += increment);
Value of the pointer will be changed in place.- Parameters:
increment
-- Returns:
- same pointer instance with modified address
-
plus
public CPointerMutable<T> plus(int value) throws java.io.IOException
add(int)
is different toplus(int)
. Whileadd(int)
modifies the address in-placeplus(int)
returns new instance with the result of the addition. Allows (almost) equivalent handling as operator.int *p, *a; a = p = .. ; a = (p+1)+1;
same asCPointerMutable
where the post conditionp, a; p = a = .. ; p = (p.plus(1)).plus(1); post condition: (p != a)
holds.
-
assign
public void assign(long address) throws java.io.IOException
Equivalent toint* p; int* a = ..; p = a;
- Parameters:
address
-- Throws:
java.io.IOException
-
assign
public void assign(CPointer<T> address) throws java.io.IOException
Equivalent toint* p; int* a = ..; p = a;
- Parameters:
address
- new address- Throws:
java.io.IOException
-
value
public long value()
Returns the value of the address.
-
-