Package com.sun.jna

Klasse Memory

Alle implementierten Schnittstellen:
Closeable, AutoCloseable
Bekannte direkte Unterklassen:
StringArray

public class Memory extends Pointer implements Closeable
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
    Modifizierer und Typ
    Feld
    Beschreibung
    protected long
     

    Von Klasse geerbte Felder com.sun.jna.Pointer

    NULL, peer
  • Konstruktorübersicht

    Konstruktoren
    Modifizierer
    Konstruktor
    Beschreibung
    protected
     
     
    Memory(long size)
    Allocate space in the native heap via a call to C's malloc.
  • Methodenübersicht

    Modifizierer und Typ
    Methode
    Beschreibung
    align(int 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.
    void
    Zero the full extent of this memory region.
    void
    Free the native memory and set peer to zero
    protected void
    Veraltet.
    static void
    Dispose of all allocated memory.
    Dumps the contents of this memory object.
    protected static void
    free(long p)
     
    byte
    getByte(long offset)
    Indirect the native pointer to malloc space, a la Pointer.getByte.
    getByteBuffer(long offset, long length)
    Get a ByteBuffer mapped to a portion of this memory.
    char
    getChar(long offset)
    Indirect the native pointer to malloc space, a la Pointer.getByte.
    double
    getDouble(long offset)
    Indirect the native pointer to malloc space, a la Pointer.getDouble.
    float
    getFloat(long offset)
    Indirect the native pointer to malloc space, a la Pointer.getFloat.
    int
    getInt(long offset)
    Indirect the native pointer to malloc space, a la Pointer.getInt.
    long
    getLong(long offset)
    Indirect the native pointer to malloc space, a la Pointer.getLong.
    getPointer(long offset)
    Indirect the native pointer to malloc space, a la Pointer.getPointer.
    short
    getShort(long offset)
    Indirect the native pointer to malloc space, a la Pointer.getShort.
    getString(long offset, String encoding)
    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 long
    malloc(long size)
     
    static void
    Force cleanup of memory that has associated NIO Buffers which have been GC'd.
    void
    read(long bOff, byte[] buf, int index, int length)
    Indirect the native pointer to malloc space, a la Pointer.read.
    void
    read(long bOff, char[] buf, int index, int length)
    Indirect the native pointer to malloc space, a la Pointer.read.
    void
    read(long bOff, double[] buf, int index, int length)
    Indirect the native pointer to malloc space, a la Pointer.read.
    void
    read(long bOff, float[] buf, int index, int length)
    Indirect the native pointer to malloc space, a la Pointer.read.
    void
    read(long bOff, int[] buf, int index, int length)
    Indirect the native pointer to malloc space, a la Pointer.read.
    void
    read(long bOff, long[] buf, int index, int length)
    Indirect the native pointer to malloc space, a la Pointer.read.
    void
    read(long bOff, short[] buf, int index, int length)
    Indirect the native pointer to malloc space, a la Pointer.read.
    void
    read(long bOff, Pointer[] buf, int index, int length)
    Indirect the native pointer to malloc space, a la Pointer.read.
    void
    setByte(long offset, byte value)
    Indirect the native pointer to malloc space, a la Pointer.setByte.
    void
    setChar(long offset, char value)
    Indirect the native pointer to malloc space, a la Pointer.setChar.
    void
    setDouble(long offset, double value)
    Indirect the native pointer to malloc space, a la Pointer.setDouble.
    void
    setFloat(long offset, float value)
    Indirect the native pointer to malloc space, a la Pointer.setFloat.
    void
    setInt(long offset, int value)
    Indirect the native pointer to malloc space, a la Pointer.setInt.
    void
    setLong(long offset, long value)
    Indirect the native pointer to malloc space, a la Pointer.setLong.
    void
    setPointer(long offset, Pointer value)
    Indirect the native pointer to malloc space, a la Pointer.setPointer.
    void
    setShort(long offset, short value)
    Indirect the native pointer to malloc space, a la Pointer.setShort.
    void
    setString(long offset, String value, String encoding)
    Copy string value to the location being pointed to, using the requested encoding.
    void
    setWideString(long offset, String value)
    Copy string value to 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.
    long
     
     
    boolean
    Returns false if the memory has been freed.
    void
    write(long bOff, byte[] buf, int index, int length)
    Indirect the native pointer to malloc space, a la Pointer.write.
    void
    write(long bOff, char[] buf, int index, int length)
    Indirect the native pointer to malloc space, a la Pointer.write.
    void
    write(long bOff, double[] buf, int index, int length)
    Indirect the native pointer to malloc space, a la Pointer.write.
    void
    write(long bOff, float[] buf, int index, int length)
    Indirect the native pointer to malloc space, a la Pointer.write.
    void
    write(long bOff, int[] buf, int index, int length)
    Indirect the native pointer to malloc space, a la Pointer.write.
    void
    write(long bOff, long[] buf, int index, int length)
    Indirect the native pointer to malloc space, a la Pointer.write.
    void
    write(long bOff, short[] buf, int index, int length)
    Indirect the native pointer to malloc space, a la Pointer.write.
    void
    write(long bOff, Pointer[] buf, int index, int length)
    Indirect the native pointer to malloc space, a la Pointer.write.

    Von Klasse geerbte Methoden java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Felddetails

    • size

      protected long size
  • Konstruktordetails

    • Memory

      public Memory(long size)
      Allocate space in the native heap via a call to C's malloc.
      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.
    • share

      public Pointer share(long offset)
      Provide a view of this memory using the given offset as the base address. The returned Pointer will have a size equal to that of the original minus the offset.
      Setzt außer Kraft:
      share in Klasse Pointer
      Löst aus:
      IndexOutOfBoundsException - if the requested memory is outside the allocated bounds.
    • share

      public Pointer 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. Maintains a reference to the original Memory object to avoid GC as long as the shared memory is referenced.
      Setzt außer Kraft:
      share in Klasse Pointer
      Löst aus:
      IndexOutOfBoundsException - if the requested memory is outside the allocated bounds.
    • align

      public Memory align(int byteBoundary)
      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:
      close in Schnittstelle AutoCloseable
      Angegeben von:
      close in Schnittstelle Closeable
    • dispose

      @Deprecated protected void 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 to malloc space, a la Pointer.read. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
      Setzt außer Kraft:
      read in Klasse Pointer
      Parameter:
      bOff - byte offset from pointer from which data is copied
      buf - byte array into which data is copied
      index - array index to which data is copied
      length - number of elements from native pointer that must be copied
      Siehe auch:
    • read

      public void read(long bOff, short[] buf, int index, int length)
      Indirect the native pointer to malloc space, a la Pointer.read. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
      Setzt außer Kraft:
      read in Klasse Pointer
      Parameter:
      bOff - byte offset from pointer from which data is copied
      buf - short array into which data is copied
      index - array index to which data is copied
      length - number of elements from native pointer that must be copied
      Siehe auch:
    • read

      public void read(long bOff, char[] buf, int index, int length)
      Indirect the native pointer to malloc space, a la Pointer.read. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
      Setzt außer Kraft:
      read in Klasse Pointer
      Parameter:
      bOff - byte offset from pointer from which data is copied
      buf - char array into which data is copied
      index - array index to which data is copied
      length - number of elements from native pointer that must be copied
      Siehe auch:
    • read

      public void read(long bOff, int[] buf, int index, int length)
      Indirect the native pointer to malloc space, a la Pointer.read. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
      Setzt außer Kraft:
      read in Klasse Pointer
      Parameter:
      bOff - byte offset from pointer from which data is copied
      buf - int array into which data is copied
      index - array index to which data is copied
      length - number of elements from native pointer that must be copied
      Siehe auch:
    • read

      public void read(long bOff, long[] buf, int index, int length)
      Indirect the native pointer to malloc space, a la Pointer.read. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
      Setzt außer Kraft:
      read in Klasse Pointer
      Parameter:
      bOff - byte offset from pointer from which data is copied
      buf - long array into which data is copied
      index - array index to which data is copied
      length - number of elements from native pointer that must be copied
      Siehe auch:
    • read

      public void read(long bOff, float[] buf, int index, int length)
      Indirect the native pointer to malloc space, a la Pointer.read. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
      Setzt außer Kraft:
      read in Klasse Pointer
      Parameter:
      bOff - byte offset from pointer from which data is copied
      buf - float array into which data is copied
      index - array index to which data is copied
      length - number of elements from native pointer that must be copied
      Siehe auch:
    • read

      public void read(long bOff, double[] buf, int index, int length)
      Indirect the native pointer to malloc space, a la Pointer.read. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
      Setzt außer Kraft:
      read in Klasse Pointer
      Parameter:
      bOff - byte offset from pointer from which data is copied
      buf - double array into which data is copied
      index - array index to which data is copied
      length - number of elements from native pointer that must be copied
      Siehe auch:
    • read

      public void read(long bOff, Pointer[] buf, int index, int length)
      Indirect the native pointer to malloc space, a la Pointer.read. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
      Setzt außer Kraft:
      read in Klasse Pointer
      Parameter:
      bOff - byte offset from pointer from which data is copied
      buf - Pointer array into which data is copied
      index - array index to which data is copied
      length - number of elements from native pointer that must be copied
      Siehe auch:
    • write

      public void write(long bOff, byte[] buf, int index, int length)
      Indirect the native pointer to malloc space, a la Pointer.write. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
      Setzt außer Kraft:
      write in Klasse Pointer
      Parameter:
      bOff - byte offset from pointer into which data is copied
      buf - byte array from which to copy
      index - array index from which to start copying
      length - number of elements from buf that must be copied
      Siehe auch:
    • write

      public void write(long bOff, short[] buf, int index, int length)
      Indirect the native pointer to malloc space, a la Pointer.write. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
      Setzt außer Kraft:
      write in Klasse Pointer
      Parameter:
      bOff - byte offset from pointer into which data is copied
      buf - short array from which to copy
      index - array index from which to start copying
      length - number of elements from buf that must be copied
      Siehe auch:
    • write

      public void write(long bOff, char[] buf, int index, int length)
      Indirect the native pointer to malloc space, a la Pointer.write. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
      Setzt außer Kraft:
      write in Klasse Pointer
      Parameter:
      bOff - byte offset from pointer into which data is copied
      buf - char array from which to copy
      index - array index from which to start copying
      length - number of elements from buf that must be copied
      Siehe auch:
    • write

      public void write(long bOff, int[] buf, int index, int length)
      Indirect the native pointer to malloc space, a la Pointer.write. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
      Setzt außer Kraft:
      write in Klasse Pointer
      Parameter:
      bOff - byte offset from pointer into which data is copied
      buf - int array from which to copy
      index - array index from which to start copying
      length - number of elements from buf that must be copied
      Siehe auch:
    • write

      public void write(long bOff, long[] buf, int index, int length)
      Indirect the native pointer to malloc space, a la Pointer.write. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
      Setzt außer Kraft:
      write in Klasse Pointer
      Parameter:
      bOff - byte offset from pointer into which data is copied
      buf - long array from which to copy
      index - array index from which to start copying
      length - number of elements from buf that must be copied
      Siehe auch:
    • write

      public void write(long bOff, float[] buf, int index, int length)
      Indirect the native pointer to malloc space, a la Pointer.write. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
      Setzt außer Kraft:
      write in Klasse Pointer
      Parameter:
      bOff - byte offset from pointer into which data is copied
      buf - float array from which to copy
      index - array index from which to start copying
      length - number of elements from buf that must be copied
      Siehe auch:
    • write

      public void write(long bOff, double[] buf, int index, int length)
      Indirect the native pointer to malloc space, a la Pointer.write. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
      Setzt außer Kraft:
      write in Klasse Pointer
      Parameter:
      bOff - byte offset from pointer into which data is copied
      buf - double array from which to copy
      index - array index from which to start copying
      length - number of elements from buf that must be copied
      Siehe auch:
    • write

      public void write(long bOff, Pointer[] buf, int index, int length)
      Indirect the native pointer to malloc space, a la Pointer.write. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
      Setzt außer Kraft:
      write in Klasse Pointer
      Parameter:
      bOff - byte offset from pointer into which data is copied
      buf - Pointer array from which to copy
      index - array index from which to start copying
      length - number of elements from buf that must be copied
      Siehe auch:
    • getByte

      public byte getByte(long offset)
      Indirect the native pointer to malloc space, a la Pointer.getByte. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
      Setzt außer Kraft:
      getByte in Klasse Pointer
      Parameter:
      offset - offset from pointer to perform the indirection
      Gibt zurück:
      the byte value being pointed to
      Siehe auch:
    • getChar

      public char getChar(long offset)
      Indirect the native pointer to malloc space, a la Pointer.getByte. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
      Setzt außer Kraft:
      getChar in Klasse Pointer
      Parameter:
      offset - offset from pointer to perform the indirection
      Gibt zurück:
      the wchar_t value being pointed to
      Siehe auch:
    • getShort

      public short getShort(long offset)
      Indirect the native pointer to malloc space, a la Pointer.getShort. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
      Setzt außer Kraft:
      getShort in Klasse Pointer
      Parameter:
      offset - byte offset from pointer to perform the indirection
      Gibt zurück:
      the short value being pointed to
      Siehe auch:
    • getInt

      public int getInt(long offset)
      Indirect the native pointer to malloc space, a la Pointer.getInt. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
      Setzt außer Kraft:
      getInt in Klasse Pointer
      Parameter:
      offset - byte offset from pointer to perform the indirection
      Gibt zurück:
      the int value being pointed to
      Siehe auch:
    • getLong

      public long getLong(long offset)
      Indirect the native pointer to malloc space, a la Pointer.getLong. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
      Setzt außer Kraft:
      getLong in Klasse Pointer
      Parameter:
      offset - byte offset from pointer to perform the indirection
      Gibt zurück:
      the long value being pointed to
      Siehe auch:
    • getFloat

      public float getFloat(long offset)
      Indirect the native pointer to malloc space, a la Pointer.getFloat. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
      Setzt außer Kraft:
      getFloat in Klasse Pointer
      Parameter:
      offset - byte offset from pointer to perform the indirection
      Gibt zurück:
      the float value being pointed to
      Siehe auch:
    • getDouble

      public double getDouble(long offset)
      Indirect the native pointer to malloc space, a la Pointer.getDouble. But this method performs a bounds check to ensure that the indirection does not cause memory outside the malloced space to be accessed.
      Setzt außer Kraft:
      getDouble in Klasse Pointer
      Parameter:
      offset - byte offset from pointer to perform the indirection
      Gibt zurück:
      the double value being pointed to
      Siehe auch:
    • getPointer

      public Pointer getPointer(long offset)
      Indirect the native pointer to malloc space, a la Pointer.getPointer. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
      Setzt außer Kraft:
      getPointer in Klasse Pointer
      Parameter:
      offset - byte offset from pointer to perform the indirection
      Gibt zurück:
      a Pointer equivalent of the pointer value being pointed to, or null if the pointer value is NULL;
      Siehe auch:
    • getByteBuffer

      public ByteBuffer getByteBuffer(long offset, long length)
      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:
      getByteBuffer in Klasse Pointer
      Parameter:
      offset - byte offset from pointer to start the buffer
      length - Length of ByteBuffer
      Gibt zurück:
      a direct ByteBuffer that accesses the memory being pointed to,
    • getString

      public String getString(long offset, String encoding)
      Beschreibung aus Klasse kopiert: Pointer
      Copy native memory to a Java String using the requested encoding.
      Setzt außer Kraft:
      getString in Klasse Pointer
      Parameter:
      offset - byte offset from pointer to obtain the native string
      encoding - the desired encoding
      Gibt zurück:
      the String value being pointed to
    • getWideString

      public String getWideString(long offset)
      Beschreibung aus Klasse kopiert: Pointer
      Read a wide (const wchar_t *) string from memory.
      Setzt außer Kraft:
      getWideString in Klasse Pointer
    • setByte

      public void setByte(long offset, byte value)
      Indirect the native pointer to malloc space, a la Pointer.setByte. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
      Setzt außer Kraft:
      setByte in Klasse Pointer
      Parameter:
      offset - byte offset from pointer at which value must be set
      value - byte value to set
      Siehe auch:
    • setChar

      public void setChar(long offset, char value)
      Indirect the native pointer to malloc space, a la Pointer.setChar. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
      Setzt außer Kraft:
      setChar in Klasse Pointer
      Parameter:
      offset - byte offset from pointer at which value must be set
      value - char value to set
      Siehe auch:
    • setShort

      public void setShort(long offset, short value)
      Indirect the native pointer to malloc space, a la Pointer.setShort. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
      Setzt außer Kraft:
      setShort in Klasse Pointer
      Parameter:
      offset - byte offset from pointer at which value must be set
      value - short value to set
      Siehe auch:
    • setInt

      public void setInt(long offset, int value)
      Indirect the native pointer to malloc space, a la Pointer.setInt. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
      Setzt außer Kraft:
      setInt in Klasse Pointer
      Parameter:
      offset - byte offset from pointer at which value must be set
      value - int value to set
      Siehe auch:
    • setLong

      public void setLong(long offset, long value)
      Indirect the native pointer to malloc space, a la Pointer.setLong. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
      Setzt außer Kraft:
      setLong in Klasse Pointer
      Parameter:
      offset - byte offset from pointer at which value must be set
      value - long value to set
      Siehe auch:
    • setFloat

      public void setFloat(long offset, float value)
      Indirect the native pointer to malloc space, a la Pointer.setFloat. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
      Setzt außer Kraft:
      setFloat in Klasse Pointer
      Parameter:
      offset - byte offset from pointer at which value must be set
      value - float value to set
      Siehe auch:
    • setDouble

      public void setDouble(long offset, double value)
      Indirect the native pointer to malloc space, a la Pointer.setDouble. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
      Setzt außer Kraft:
      setDouble in Klasse Pointer
      Parameter:
      offset - byte offset from pointer at which value must be set
      value - double value to set
      Siehe auch:
    • setPointer

      public void setPointer(long offset, Pointer value)
      Indirect the native pointer to malloc space, a la Pointer.setPointer. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
      Setzt außer Kraft:
      setPointer in Klasse Pointer
      Parameter:
      offset - byte offset from pointer at which value must be set
      value - Pointer holding the actual pointer value to set, which may be null to indicate a NULL pointer.
      Siehe auch:
    • setString

      public void setString(long offset, String value, String encoding)
      Beschreibung aus Klasse kopiert: Pointer
      Copy string value to the location being pointed to, using the requested encoding.
      Setzt außer Kraft:
      setString in Klasse Pointer
      Parameter:
      offset - byte offset from pointer at which characters in value must be set
      value - java.lang.String value to set
      encoding - desired encoding
    • setWideString

      public void setWideString(long offset, String value)
      Beschreibung aus Klasse kopiert: Pointer
      Copy string value to the location being pointed to as a wide string (wchar_t*).
      Setzt außer Kraft:
      setWideString in Klasse Pointer
      Parameter:
      offset - byte offset from pointer at which characters in value must be set
      value - java.lang.String value to set
    • toString

      public String toString()
      Setzt außer Kraft:
      toString in Klasse Pointer
    • free

      protected static void free(long p)
    • malloc

      protected static long malloc(long size)
    • dump

      public String dump()
      Dumps the contents of this memory object.