Pointer to memory obtained from the native heap via a
call to malloc.
In some cases it might be necessary to use memory obtained from
malloc. For example, Memory helps
accomplish the following idiom:
void *buf = malloc(BUF_LEN * sizeof(char)); call_some_function(buf); free(buf);
The finalize method will free allocated memory when
this object is no longer referenced.
Pointer
| Modifier and Type | Class and Description |
|---|---|
| private class | Memory.SharedMemory
Provide a view into the original memory. |
| Modifier and Type | Field and Description |
|---|---|
| protected long |
| Access | Constructor and Description |
|---|---|
| public | Memory(long
number of bytes of space to allocate size)Allocate space in the native heap via a call to C's |
| protected |
| Modifier and Type | Method and Description |
|---|---|
| public Pointer | align(int
Align memory to this number of bytes; should be a
power of two. byteBoundary)Provide a view onto this structure with the given alignment. |
| protected void | boundsCheck(long off, long sz)
Check that indirection won't cause us to write outside the malloc'ed space. |
| public void | |
| protected void | finalize()
Overrides java. |
| pack-priv static native void | |
| public byte | getByte(long
offset from pointer to perform the indirection offset)Overrides com. malloc space, a la
Pointer.getByte.
|
| public ByteBuffer | Returns: a direct ByteBuffer that accesses the memory being pointed to,byte offset from pointer to start the buffer offset, long Length of ByteBuffer length)Overrides com. |
| public char | getChar(long
offset from pointer to perform the indirection offset)Overrides com. malloc space, a la
Pointer.getByte.
|
| public double | getDouble(long
byte offset from pointer to perform the indirection offset)Overrides com. malloc space, a la
Pointer.getDouble.
|
| public float | getFloat(long
byte offset from pointer to perform the indirection offset)Overrides com. malloc space, a la
Pointer.getFloat.
|
| public int | getInt(long
byte offset from pointer to perform the indirection offset)Overrides com. malloc space, a la
Pointer.getInt.
|
| public long | getLong(long
byte offset from pointer to perform the indirection offset)Overrides com. malloc space, a la
Pointer.getLong.
|
| public Pointer | getPointer(long
byte offset from pointer to perform the indirection offset)Overrides com. malloc space, a la
Pointer.getPointer.
|
| public short | getShort(long
byte offset from pointer to perform the indirection offset)Overrides com. malloc space, a la
Pointer.getShort.
|
| public long | |
| public String | getString(long
byte offset from pointer to obtain the native string
v * @param wide whether to convert from a wide or standard C string offset, boolean wide)Overrides com. malloc space, a la
Pointer.getString.
|
| public boolean | |
| pack-priv static native long | |
| public void | read(long
byte offset from pointer into which data is copied bOff, byte[] byte array into which data is copiedarray index from which to start copying index, int number of elements from native pointer that must be copied length)Overrides com. malloc space, a la
Pointer.read.
|
| public void | read(long
byte offset from pointer from which data is copied bOff, short[] short array into which data is copiedarray index to which data is copied index, int number of elements from native pointer that must be copied length)Overrides com. malloc space, a la
Pointer.read.
|
| public void | read(long
byte offset from pointer from which data is copied bOff, char[] char array into which data is copiedarray index to which data is copied index, int number of elements from native pointer that must be copied length)Overrides com. malloc space, a la
Pointer.read.
|
| public void | read(long
byte offset from pointer from which data is copied bOff, int[] int array into which data is copiedarray index to which data is copied index, int number of elements from native pointer that must be copied length)Overrides com. malloc space, a la
Pointer.read.
|
| public void | read(long
byte offset from pointer from which data is copied bOff, long[] long array into which data is copiedarray index to which data is copied index, int number of elements from native pointer that must be copied length)Overrides com. malloc space, a la
Pointer.read.
|
| public void | read(long
byte offset from pointer from which data is copied bOff, float[] float array into which data is copiedarray index to which data is copied index, int number of elements from native pointer that must be copied length)Overrides com. malloc space, a la
Pointer.read.
|
| public void | read(long
byte offset from pointer from which data is copied bOff, double[] double array into which data is copiedarray index to which data is copied index, int number of elements from native pointer that must be copied length)Overrides com. malloc space, a la
Pointer.read.
|
| public void | setByte(long
byte offset from pointer at which offset, byte value
must be setbyte value to setOverrides com. malloc space, a la
Pointer.setByte.
|
| public void | setChar(long
byte offset from pointer at which offset, char value
must be setchar value to setOverrides com. malloc space, a la
Pointer.setChar.
|
| public void | setDouble(long
byte offset from pointer at which offset, double value
must be setdouble value to setOverrides com. malloc space, a la
Pointer.setDouble.
|
| public void | setFloat(long
byte offset from pointer at which offset, float value
must be setfloat value to setOverrides com. malloc space, a la
Pointer.setFloat.
|
| public void | setInt(long
byte offset from pointer at which offset, int value
must be setint value to setOverrides com. malloc space, a la
Pointer.setInt.
|
| public void | setLong(long
byte offset from pointer at which offset, long value
must be setlong value to setOverrides com. malloc space, a la
Pointer.setLong.
|
| public void | setPointer(long
byte offset from pointer at which offset, Pointer value
must be setPointer holding the actual pointer value to
set, which may be null to indicate a NULL
pointer.Overrides com. malloc space, a la
Pointer.setPointer.
|
| public void | setShort(long
byte offset from pointer at which offset, short value
must be setshort value to setOverrides com. malloc space, a la
Pointer.setShort.
|
| public void | setString(long
byte offset from pointer at which characters in
offset, String value must be setjava.lang.String value to setwhether to write the native string as an array of
wide)wchar_t. If false, writes as a NUL-terminated array of
char using the default platform encoding.Overrides com. malloc space, a la
Pointer.setString.
|
| public Pointer | share(long offset)
Overrides com. |
| public Pointer | share(long offset, long sz)
Overrides com. |
| public String | |
| public void | write(long
byte offset from pointer into which data is copied bOff, byte[] byte array from which to copyarray index from which to start copying index, int number of elements from length)buf that must be
copiedOverrides com. malloc space, a la
Pointer.write.
|
| public void | write(long
byte offset from pointer into which data is copied bOff, short[] short array from which to copyarray index from which to start copying index, int number of elements from length)buf that must be
copiedOverrides com. malloc space, a la
Pointer.write.
|
| public void | write(long
byte offset from pointer into which data is copied bOff, char[] char array from which to copyarray index from which to start copying index, int number of elements from length)buf that must be
copiedOverrides com. malloc space, a la
Pointer.write.
|
| public void | write(long
byte offset from pointer into which data is copied bOff, int[] int array from which to copyarray index from which to start copying index, int number of elements from length)buf that must be
copiedOverrides com. malloc space, a la
Pointer.write.
|
| public void | write(long
byte offset from pointer into which data is copied bOff, long[] long array from which to copyarray index from which to start copying index, int number of elements from length)buf that must be
copiedOverrides com. malloc space, a la
Pointer.write.
|
| public void | write(long
byte offset from pointer into which data is copied bOff, float[] float array from which to copyarray index from which to start copying index, int number of elements from length)buf that must be
copiedOverrides com. malloc space, a la
Pointer.write.
|
| public void | write(long
byte offset from pointer into which data is copied bOff, double[] double array from which to copyarray index from which to start copying index, int number of elements from length)buf that must be
copiedOverrides com. malloc space, a la
Pointer.write.
|
| size | back to summary |
|---|---|
| protected long size | |
| Memory | back to summary |
|---|---|
| public Memory(long size) Allocate space in the native heap via a call to C's
| |
| Memory | back to summary |
|---|---|
| protected Memory() | |
| align | back to summary |
|---|---|
| public Pointer align(int byteBoundary) Provide a view onto this structure with the given alignment.
| |
| boundsCheck | back to summary |
|---|---|
| protected void boundsCheck(long off, long sz) Check that indirection won't cause us to write outside the malloc'ed space. | |
| clear | back to summary |
|---|---|
| public void clear() Zero the full extent of this memory region. | |
| finalize | back to summary |
|---|---|
| protected void finalize() Overrides java. Doc from java. Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.
A subclass overrides the
When running in a Java virtual machine in which finalization has been
disabled or removed, the garbage collector will never call
The general contract of
The
The Java programming language does not guarantee which thread will
invoke the
After the
The
Any exception thrown by the | |
| free | back to summary |
|---|---|
| pack-priv static native void free(long ptr) Call the real native free | |
| getByte | back to summary |
|---|---|
| public byte getByte(long offset) Overrides com. Indirect the native pointer to
| |
| getByteBuffer | back to summary |
|---|---|
| public ByteBuffer getByteBuffer(long offset, long length) Overrides com. Get a ByteBuffer mapped to a portion of this memory.
| |
| getChar | back to summary |
|---|---|
| public char getChar(long offset) Overrides com. Indirect the native pointer to
| |
| getDouble | back to summary |
|---|---|
| public double getDouble(long offset) Overrides com. Indirect the native pointer to
| |
| getFloat | back to summary |
|---|---|
| public float getFloat(long offset) Overrides com. Indirect the native pointer to
| |
| getInt | back to summary |
|---|---|
| public int getInt(long offset) Overrides com. Indirect the native pointer to
| |
| getLong | back to summary |
|---|---|
| public long getLong(long offset) Overrides com. Indirect the native pointer to
| |
| getPointer | back to summary |
|---|---|
| public Pointer getPointer(long offset) Overrides com. Indirect the native pointer to
| |
| getShort | back to summary |
|---|---|
| public short getShort(long offset) Overrides com. Indirect the native pointer to
| |
| getSize | back to summary |
|---|---|
| public long getSize() | |
| getString | back to summary |
|---|---|
| public String getString(long offset, boolean wide) Overrides com. Indirect the native pointer to
| |
| isValid | back to summary |
|---|---|
| public boolean isValid() Returns false if the memory has been freed. | |
| malloc | back to summary |
|---|---|
| pack-priv static native long malloc(long size) Call the real native malloc | |
| read | back to summary |
|---|---|
| public void read(long bOff, byte[] buf, int index, int length) Overrides com. Indirect the native pointer to
| |
| read | back to summary |
|---|---|
| public void read(long bOff, short[] buf, int index, int length) Overrides com. Indirect the native pointer to
| |
| read | back to summary |
|---|---|
| public void read(long bOff, char[] buf, int index, int length) Overrides com. Indirect the native pointer to
| |
| read | back to summary |
|---|---|
| public void read(long bOff, int[] buf, int index, int length) Overrides com. Indirect the native pointer to
| |
| read | back to summary |
|---|---|
| public void read(long bOff, long[] buf, int index, int length) Overrides com. Indirect the native pointer to
| |
| read | back to summary |
|---|---|
| public void read(long bOff, float[] buf, int index, int length) Overrides com. Indirect the native pointer to
| |
| read | back to summary |
|---|---|
| public void read(long bOff, double[] buf, int index, int length) Overrides com. Indirect the native pointer to
| |
| setByte | back to summary |
|---|---|
| public void setByte(long offset, byte value) Overrides com. Indirect the native pointer to
| |
| setChar | back to summary |
|---|---|
| public void setChar(long offset, char value) Overrides com. Indirect the native pointer to
| |
| setDouble | back to summary |
|---|---|
| public void setDouble(long offset, double value) Overrides com. Indirect the native pointer to
| |
| setFloat | back to summary |
|---|---|
| public void setFloat(long offset, float value) Overrides com. Indirect the native pointer to
| |
| setInt | back to summary |
|---|---|
| public void setInt(long offset, int value) Overrides com. Indirect the native pointer to
| |
| setLong | back to summary |
|---|---|
| public void setLong(long offset, long value) Overrides com. Indirect the native pointer to
| |
| setPointer | back to summary |
|---|---|
| public void setPointer(long offset, Pointer value) Overrides com. Indirect the native pointer to
| |
| setShort | back to summary |
|---|---|
| public void setShort(long offset, short value) Overrides com. Indirect the native pointer to
| |
| setString | back to summary |
|---|---|
| public void setString(long offset, String value, boolean wide) Overrides com. Indirect the native pointer to
| |
| share | back to summary |
|---|---|
| public Pointer share(long offset) Overrides com. Provide a view onto this structure from the given offset. The
returned
| |
| share | back to summary |
|---|---|
| public Pointer share(long offset, long sz) Overrides com. Provide a view onto this structure from the given offset.
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides com. Doc from java. Returns a string representation of the object.
| |
| write | back to summary |
|---|---|
| public void write(long bOff, byte[] buf, int index, int length) Overrides com. Indirect the native pointer to
| |
| write | back to summary |
|---|---|
| public void write(long bOff, short[] buf, int index, int length) Overrides com. Indirect the native pointer to
| |
| write | back to summary |
|---|---|
| public void write(long bOff, char[] buf, int index, int length) Overrides com. Indirect the native pointer to
| |
| write | back to summary |
|---|---|
| public void write(long bOff, int[] buf, int index, int length) Overrides com. Indirect the native pointer to
| |
| write | back to summary |
|---|---|
| public void write(long bOff, long[] buf, int index, int length) Overrides com. Indirect the native pointer to
| |
| write | back to summary |
|---|---|
| public void write(long bOff, float[] buf, int index, int length) Overrides com. Indirect the native pointer to
| |
| write | back to summary |
|---|---|
| public void write(long bOff, double[] buf, int index, int length) Overrides com. Indirect the native pointer to
| |