|
" 2013 FRC Java API " |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.sun.squawk.realtime.RawMemoryAccess
com.sun.squawk.realtime.RawMemoryFloatAccess
com.sun.cldc.jna.Pointer
public class Pointer
A pointer to native memory, based on RTSJ-like RawMemoryAccesss semantics. Otherise similar to the Memory class in JNA. All pointers have a size, so memory access through a pointer is range-checked. A pointer can either have a dedicated backing buffer of native memory (from malloc or similar), or it may be a "shared" subset of some other Pointer.
Field Summary |
---|
Fields inherited from class com.sun.squawk.realtime.RawMemoryAccess |
---|
vbase |
Constructor Summary | |
---|---|
Pointer(Address base,
int size)
Create a pointer that refers to a memory range from [base..base+size). |
|
Pointer(Address base,
UWord size)
Create a pointer that refers to a memory range from [base..base+size). |
|
Pointer(int size)
Create a pointer and allocate backing native memory of the requestsed size. |
|
Pointer(long base,
int size)
Create a pointer that refers to a memory range from [base..base+size). |
Method Summary | |
---|---|
Address |
address()
Gets the virtual memory location at which the memory region is mapped. |
Pointer |
align(int byteAlignment)
Create a new pointer that is a subset of this pointer, but is aligned to byteAlignment |
void |
clear()
Zero memory |
void |
clear(int size)
Zero the first "size" bytes of memory |
static void |
copyBytes(Pointer src,
int srcOffset,
Pointer dst,
int dstOffset,
int len)
Copy len bytes from src to dst starting at the given offsets. |
static Pointer |
createStringBuffer(String value)
Create a native buffer containing the C-string version of the String vaue . |
void |
free()
Free the backing native memory for this pointer. |
Pointer |
getPointer(int offset,
int size)
Read a ptr value from memory at offset, and construct a new pointer representing the data stored there... |
int |
getSize()
Gets the size of the memory |
String |
getString(int offset)
Create a Java string from a C string pointer to by this pointer at offset |
boolean |
isValid()
|
static String |
NativeUnsafeGetString(Address cstr)
Create a Java string from a C string pointer |
static Pointer |
NULL()
|
void |
release()
Free the backing native memory for this pointer if this pointer was created by allocating memory. |
void |
setPointer(int offset,
Pointer ptr)
Set the word at offset from this pointer to the the address contained in
ptr . |
void |
setString(int offset,
String value)
Copy string value to the location at offset . |
Pointer |
share(long offset)
Create a new pointer that is a subset of this pointer, starting from offset |
Pointer |
share(long offset,
long size)
Create a new pointer that is a subset of this pointer, starting from offset |
String |
toString()
Returns a string representation of the object. |
Methods inherited from class com.sun.squawk.realtime.RawMemoryFloatAccess |
---|
getDouble, getDoubles, getFloat, getFloats, setDouble, setDoubles, setFloat, setFloats |
Methods inherited from class com.sun.squawk.realtime.RawMemoryAccess |
---|
checkBounds, checkMultiBounds, checkMultiRead, checkMultiWrite, getAddress, getByte, getBytes, getInt, getInts, getLong, getLongs, getMappedAddress, getShort, getShorts, invalidate, map, map, map, setByte, setBytes, setInt, setInts, setLong, setLongs, setShort, setShorts, size, wasMalloced |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Pointer(int size) throws SizeOutOfBoundsException, OutOfMemoryError
free()
.
size
- the number of bytes that can be referenced from this pointer
SizeOutOfBoundsException
- if the size is negative or too large
OutOfMemoryError
- if the backing memory cannot be allocatedpublic Pointer(long base, int size)
base
- the base address of the pointersize
- the number of bytes that can be referenced from this pointer
SecurityException
- if the memory range intersets the Java heap
OffsetOutOfBoundsException
- Thrown if the address is invalid.
SizeOutOfBoundsException
- Thrown if the size is negative or
extends into an invalid range of memory.public Pointer(Address base, UWord size)
base
- the base address of the pointersize
- the number of bytes that can be referenced from this pointer
SecurityException
- if the memory range intersets the Java heap
OffsetOutOfBoundsException
- Thrown if the address is invalid.
SizeOutOfBoundsException
- Thrown if the size is negative or
extends into an invalid range of memory.public Pointer(Address base, int size)
base
- the base address of the pointersize
- the number of bytes that can be referenced from this pointer
SecurityException
- if the memory range intersets the Java heap
OffsetOutOfBoundsException
- Thrown if the address is invalid.
SizeOutOfBoundsException
- Thrown if the size is negative or
extends into an invalid range of memory.Method Detail |
---|
public static Pointer NULL()
public Pointer share(long offset)
offset
- offset from this pointer to start the new pointer
public Pointer share(long offset, long size)
offset
- offset from this pointer to start the new pointersize
- size of the new pointer
public Pointer align(int byteAlignment)
byteAlignment
-
IllegalArgumentException
- if byteAlignment is not a power of 2public String toString()
Object
toString
method returns a string that
"textually represents" this object. The result should
be a concise but informative representation that is easy for a
person to read.
It is recommended that all subclasses override this method.
The toString
method for class Object
returns a string consisting of the name of the class of which the
object is an instance, the at-sign character `@
', and
the unsigned hexadecimal representation of the hash code of the
object. In other words, this method returns a string equal to the
value of:
getClass().getName() + '@' + Integer.toHexString(hashCode())
toString
in class Object
public final Address address()
IllegalStateException
- Thrown if the raw memory object is not in the
mapped state.public final int getSize()
public void clear(int size)
size
- number of bytespublic void clear()
public Pointer getPointer(int offset, int size)
offset
- offset from this
pointer that conatins a memory location that is an address.size
- the size that the new pointer should have
public void setPointer(int offset, Pointer ptr)
offset
from this
pointer to the the address contained in
ptr
.
offset
- offset in bytes from this pointer's base to the word to be set.ptr
- the value that will be setpublic String getString(int offset)
offset
- the byte offset of the c string from the base of this pointer
public static String NativeUnsafeGetString(Address cstr)
cstr
-
public final void setString(int offset, String value)
offset
. Convert the data in value
to a
NULL-terminated C string, converted to native encoding.
offset
- the byte offset of the c string from the base of this pointervalue
- the string to copypublic final void free() throws IllegalStateException
IllegalStateException
- if free has already been called on this pointer.public final void release() throws IllegalStateException
IllegalStateException
- if release has already been called on this pointer.public final boolean isValid()
public static Pointer createStringBuffer(String value) throws OutOfMemoryError
vaue
.
The returned pointer should be freed when not needed.
value
- the string to copy
OutOfMemoryError
- if the underlying memory cannot be allocatedpublic static void copyBytes(Pointer src, int srcOffset, Pointer dst, int dstOffset, int len) throws OffsetOutOfBoundsException, SizeOutOfBoundsException
len
bytes from src
to dst
starting at the given offsets.
Throws exception if the memory ranges specified for src
dst dst
stray outside the
valid ranges for those Pointers
.
src
- Pointer to the source bytessrcOffset
- offset in bytes to start copying fromdst
- Pointer to the destination bytesdstOffset
- offset in bytes to start copying tolen
- number of bytes to copy
OffsetOutOfBoundsException
- Thrown if an offset is negative or greater than the size of the
raw memory area. The role of the SizeOutOfBoundsException
somewhat overlaps
this exception since it is thrown if the offset is within the object but outside the
mapped area.
SizeOutOfBoundsException
- Thrown if the object is not mapped,
or if the requested memory raange falls in an invalid address range.
|
" 2013 FRC Java API " |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |