Package com.sun.jna
Klasse Memory
java.lang.Object
com.sun.jna.Pointer
com.sun.jna.Memory
- Alle implementierten Schnittstellen:
Closeable,AutoCloseable
- Bekannte direkte Unterklassen:
StringArray
A
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);
- Autor:
- Sheng Liang, originator, Todd Fast, suitability modifications, Timothy Wall
- Siehe auch:
-
Feldübersicht
Felder -
Konstruktorübersicht
Konstruktoren -
Methodenübersicht
Modifizierer und TypMethodeBeschreibungalign(int byteBoundary) Provide a view onto this structure with the given alignment.protected voidboundsCheck(long off, long sz) Check that indirection won't cause us to write outside the malloc'ed space.voidclear()Zero the full extent of this memory region.voidclose()Free the native memory and set peer to zeroprotected voiddispose()Veraltet.static voidDispose of all allocated memory.dump()Dumps the contents of this memory object.protected static voidfree(long p) bytegetByte(long offset) Indirect the native pointer tomallocspace, a laPointer.getByte.getByteBuffer(long offset, long length) Get a ByteBuffer mapped to a portion of this memory.chargetChar(long offset) Indirect the native pointer tomallocspace, a laPointer.getByte.doublegetDouble(long offset) Indirect the native pointer tomallocspace, a laPointer.getDouble.floatgetFloat(long offset) Indirect the native pointer tomallocspace, a laPointer.getFloat.intgetInt(long offset) Indirect the native pointer tomallocspace, a laPointer.getInt.longgetLong(long offset) Indirect the native pointer tomallocspace, a laPointer.getLong.getPointer(long offset) Indirect the native pointer tomallocspace, a laPointer.getPointer.shortgetShort(long offset) Indirect the native pointer tomallocspace, a laPointer.getShort.Copy native memory to a Java String using the requested encoding.getWideString(long offset) Read a wide (const wchar_t *) string from memory.protected static longmalloc(long size) static voidpurge()Force cleanup of memory that has associated NIO Buffers which have been GC'd.voidread(long bOff, byte[] buf, int index, int length) Indirect the native pointer tomallocspace, a laPointer.read.voidread(long bOff, char[] buf, int index, int length) Indirect the native pointer tomallocspace, a laPointer.read.voidread(long bOff, double[] buf, int index, int length) Indirect the native pointer tomallocspace, a laPointer.read.voidread(long bOff, float[] buf, int index, int length) Indirect the native pointer tomallocspace, a laPointer.read.voidread(long bOff, int[] buf, int index, int length) Indirect the native pointer tomallocspace, a laPointer.read.voidread(long bOff, long[] buf, int index, int length) Indirect the native pointer tomallocspace, a laPointer.read.voidread(long bOff, short[] buf, int index, int length) Indirect the native pointer tomallocspace, a laPointer.read.voidIndirect the native pointer tomallocspace, a laPointer.read.voidsetByte(long offset, byte value) Indirect the native pointer tomallocspace, a laPointer.setByte.voidsetChar(long offset, char value) Indirect the native pointer tomallocspace, a laPointer.setChar.voidsetDouble(long offset, double value) Indirect the native pointer tomallocspace, a laPointer.setDouble.voidsetFloat(long offset, float value) Indirect the native pointer tomallocspace, a laPointer.setFloat.voidsetInt(long offset, int value) Indirect the native pointer tomallocspace, a laPointer.setInt.voidsetLong(long offset, long value) Indirect the native pointer tomallocspace, a laPointer.setLong.voidsetPointer(long offset, Pointer value) Indirect the native pointer tomallocspace, a laPointer.setPointer.voidsetShort(long offset, short value) Indirect the native pointer tomallocspace, a laPointer.setShort.voidCopy stringvalueto the location being pointed to, using the requested encoding.voidsetWideString(long offset, String value) Copy stringvalueto the location being pointed to as a wide string (wchar_t*).share(long offset) Provide a view of this memory using the given offset as the base address.share(long offset, long sz) Provide a view of this memory using the given offset as the base address, bounds-limited with the given size.longsize()toString()booleanvalid()Returns false if the memory has been freed.voidwrite(long bOff, byte[] buf, int index, int length) Indirect the native pointer tomallocspace, a laPointer.write.voidwrite(long bOff, char[] buf, int index, int length) Indirect the native pointer tomallocspace, a laPointer.write.voidwrite(long bOff, double[] buf, int index, int length) Indirect the native pointer tomallocspace, a laPointer.write.voidwrite(long bOff, float[] buf, int index, int length) Indirect the native pointer tomallocspace, a laPointer.write.voidwrite(long bOff, int[] buf, int index, int length) Indirect the native pointer tomallocspace, a laPointer.write.voidwrite(long bOff, long[] buf, int index, int length) Indirect the native pointer tomallocspace, a laPointer.write.voidwrite(long bOff, short[] buf, int index, int length) Indirect the native pointer tomallocspace, a laPointer.write.voidIndirect the native pointer tomallocspace, a laPointer.write.Von Klasse geerbte Methoden com.sun.jna.Pointer
clear, createConstant, createConstant, dump, equals, getByteArray, getCharArray, getDoubleArray, getFloatArray, getIntArray, getLongArray, getNativeLong, getPointerArray, getPointerArray, getShortArray, getString, getStringArray, getStringArray, getStringArray, getStringArray, getValue, getWideStringArray, getWideStringArray, hashCode, indexOf, nativeValue, nativeValue, setMemory, setNativeLong, setString, setString, setValue
-
Felddetails
-
size
protected long size
-
-
Konstruktordetails
-
Memory
public Memory(long size) Allocate space in the native heap via a call to C'smalloc.- Parameter:
size- number of bytes of space to allocate
-
Memory
protected Memory()
-
-
Methodendetails
-
purge
public static void purge()Force cleanup of memory that has associated NIO Buffers which have been GC'd. -
disposeAll
public static void disposeAll()Dispose of all allocated memory. -
align
Provide a view onto this structure with the given alignment.- Parameter:
byteBoundary- Align memory to this number of bytes; should be a power of two.- Löst aus:
IndexOutOfBoundsException- if the requested alignment can not be met.IllegalArgumentException- if the requested alignment is not a positive power of two.
-
close
public void close()Free the native memory and set peer to zero- Angegeben von:
closein SchnittstelleAutoCloseable- Angegeben von:
closein SchnittstelleCloseable
-
dispose
Veraltet. -
clear
public void clear()Zero the full extent of this memory region. -
valid
public boolean valid()Returns false if the memory has been freed. -
size
public long size() -
boundsCheck
protected void boundsCheck(long off, long sz) Check that indirection won't cause us to write outside the malloc'ed space. -
read
public void read(long bOff, byte[] buf, int index, int length) Indirect the native pointer tomallocspace, a laPointer.read. But this method performs a bounds checks to ensure that the indirection does not cause memory outside themalloced space to be accessed. -
read
public void read(long bOff, short[] buf, int index, int length) Indirect the native pointer tomallocspace, a laPointer.read. But this method performs a bounds checks to ensure that the indirection does not cause memory outside themalloced space to be accessed. -
read
public void read(long bOff, char[] buf, int index, int length) Indirect the native pointer tomallocspace, a laPointer.read. But this method performs a bounds checks to ensure that the indirection does not cause memory outside themalloced space to be accessed. -
read
public void read(long bOff, int[] buf, int index, int length) Indirect the native pointer tomallocspace, a laPointer.read. But this method performs a bounds checks to ensure that the indirection does not cause memory outside themalloced space to be accessed. -
read
public void read(long bOff, long[] buf, int index, int length) Indirect the native pointer tomallocspace, a laPointer.read. But this method performs a bounds checks to ensure that the indirection does not cause memory outside themalloced space to be accessed. -
read
public void read(long bOff, float[] buf, int index, int length) Indirect the native pointer tomallocspace, a laPointer.read. But this method performs a bounds checks to ensure that the indirection does not cause memory outside themalloced space to be accessed. -
read
public void read(long bOff, double[] buf, int index, int length) Indirect the native pointer tomallocspace, a laPointer.read. But this method performs a bounds checks to ensure that the indirection does not cause memory outside themalloced space to be accessed. -
read
Indirect the native pointer tomallocspace, a laPointer.read. But this method performs a bounds checks to ensure that the indirection does not cause memory outside themalloced space to be accessed. -
write
public void write(long bOff, byte[] buf, int index, int length) Indirect the native pointer tomallocspace, a laPointer.write. But this method performs a bounds checks to ensure that the indirection does not cause memory outside themalloced space to be accessed. -
write
public void write(long bOff, short[] buf, int index, int length) Indirect the native pointer tomallocspace, a laPointer.write. But this method performs a bounds checks to ensure that the indirection does not cause memory outside themalloced space to be accessed. -
write
public void write(long bOff, char[] buf, int index, int length) Indirect the native pointer tomallocspace, a laPointer.write. But this method performs a bounds checks to ensure that the indirection does not cause memory outside themalloced space to be accessed. -
write
public void write(long bOff, int[] buf, int index, int length) Indirect the native pointer tomallocspace, a laPointer.write. But this method performs a bounds checks to ensure that the indirection does not cause memory outside themalloced space to be accessed. -
write
public void write(long bOff, long[] buf, int index, int length) Indirect the native pointer tomallocspace, a laPointer.write. But this method performs a bounds checks to ensure that the indirection does not cause memory outside themalloced space to be accessed. -
write
public void write(long bOff, float[] buf, int index, int length) Indirect the native pointer tomallocspace, a laPointer.write. But this method performs a bounds checks to ensure that the indirection does not cause memory outside themalloced space to be accessed. -
write
public void write(long bOff, double[] buf, int index, int length) Indirect the native pointer tomallocspace, a laPointer.write. But this method performs a bounds checks to ensure that the indirection does not cause memory outside themalloced space to be accessed. -
write
Indirect the native pointer tomallocspace, a laPointer.write. But this method performs a bounds checks to ensure that the indirection does not cause memory outside themalloced space to be accessed. -
getByte
public byte getByte(long offset) Indirect the native pointer tomallocspace, a laPointer.getByte. But this method performs a bounds checks to ensure that the indirection does not cause memory outside themalloced space to be accessed. -
getChar
public char getChar(long offset) Indirect the native pointer tomallocspace, a laPointer.getByte. But this method performs a bounds checks to ensure that the indirection does not cause memory outside themalloced space to be accessed. -
getShort
public short getShort(long offset) Indirect the native pointer tomallocspace, a laPointer.getShort. But this method performs a bounds checks to ensure that the indirection does not cause memory outside themalloced space to be accessed. -
getInt
public int getInt(long offset) Indirect the native pointer tomallocspace, a laPointer.getInt. But this method performs a bounds checks to ensure that the indirection does not cause memory outside themalloced space to be accessed. -
getLong
public long getLong(long offset) Indirect the native pointer tomallocspace, a laPointer.getLong. But this method performs a bounds checks to ensure that the indirection does not cause memory outside themalloced space to be accessed. -
getFloat
public float getFloat(long offset) Indirect the native pointer tomallocspace, a laPointer.getFloat. But this method performs a bounds checks to ensure that the indirection does not cause memory outside themalloced space to be accessed. -
getDouble
public double getDouble(long offset) Indirect the native pointer tomallocspace, a laPointer.getDouble. But this method performs a bounds check to ensure that the indirection does not cause memory outside themalloced space to be accessed. -
getPointer
Indirect the native pointer tomallocspace, a laPointer.getPointer. But this method performs a bounds checks to ensure that the indirection does not cause memory outside themalloced space to be accessed.- Setzt außer Kraft:
getPointerin KlassePointer- Parameter:
offset- byte offset from pointer to perform the indirection- Gibt zurück:
- a
Pointerequivalent of the pointer value being pointed to, ornullif the pointer value isNULL; - Siehe auch:
-
getByteBuffer
Get a ByteBuffer mapped to a portion of this memory. We keep a weak reference to all ByteBuffers provided so that this memory object is not GC'd while there are still implicit outstanding references to it (it'd be nice if we could attach our own reference to the ByteBuffer, but the VM generates the object so we have no control over it).- Setzt außer Kraft:
getByteBufferin KlassePointer- Parameter:
offset- byte offset from pointer to start the bufferlength- Length of ByteBuffer- Gibt zurück:
- a direct ByteBuffer that accesses the memory being pointed to,
-
getString
Beschreibung aus Klasse kopiert:PointerCopy native memory to a Java String using the requested encoding. -
getWideString
Beschreibung aus Klasse kopiert:PointerRead a wide (const wchar_t *) string from memory.- Setzt außer Kraft:
getWideStringin KlassePointer
-
setByte
public void setByte(long offset, byte value) Indirect the native pointer tomallocspace, a laPointer.setByte. But this method performs a bounds checks to ensure that the indirection does not cause memory outside themalloced space to be accessed. -
setChar
public void setChar(long offset, char value) Indirect the native pointer tomallocspace, a laPointer.setChar. But this method performs a bounds checks to ensure that the indirection does not cause memory outside themalloced space to be accessed. -
setShort
public void setShort(long offset, short value) Indirect the native pointer tomallocspace, a laPointer.setShort. But this method performs a bounds checks to ensure that the indirection does not cause memory outside themalloced space to be accessed. -
setInt
public void setInt(long offset, int value) Indirect the native pointer tomallocspace, a laPointer.setInt. But this method performs a bounds checks to ensure that the indirection does not cause memory outside themalloced space to be accessed. -
setLong
public void setLong(long offset, long value) Indirect the native pointer tomallocspace, a laPointer.setLong. But this method performs a bounds checks to ensure that the indirection does not cause memory outside themalloced space to be accessed. -
setFloat
public void setFloat(long offset, float value) Indirect the native pointer tomallocspace, a laPointer.setFloat. But this method performs a bounds checks to ensure that the indirection does not cause memory outside themalloced space to be accessed. -
setDouble
public void setDouble(long offset, double value) Indirect the native pointer tomallocspace, a laPointer.setDouble. But this method performs a bounds checks to ensure that the indirection does not cause memory outside themalloced space to be accessed. -
setPointer
Indirect the native pointer tomallocspace, a laPointer.setPointer. But this method performs a bounds checks to ensure that the indirection does not cause memory outside themalloced space to be accessed.- Setzt außer Kraft:
setPointerin KlassePointer- Parameter:
offset- byte offset from pointer at whichvaluemust be setvalue-Pointerholding the actual pointer value to set, which may benullto indicate aNULLpointer.- Siehe auch:
-
setString
Beschreibung aus Klasse kopiert:PointerCopy stringvalueto the location being pointed to, using the requested encoding. -
setWideString
Beschreibung aus Klasse kopiert:PointerCopy stringvalueto the location being pointed to as a wide string (wchar_t*).- Setzt außer Kraft:
setWideStringin KlassePointer- Parameter:
offset- byte offset from pointer at which characters invaluemust be setvalue-java.lang.Stringvalue to set
-
toString
-
free
protected static void free(long p) -
malloc
protected static long malloc(long size) -
dump
Dumps the contents of this memory object.
-