Documentation of 'com.jstatcom.engine.CMalloc' Java class
CMalloc
com.jstatcom.engine

Class CMalloc



  • public final class CMalloc
    extends CPtr
    A CPtr to memory obtained from the C heap via a call to malloc.

    In some cases it might be necessary to use memory obtained from malloc. For example, CMalloc helps accomplish the following idiom:

                    void *buf = malloc(BUF_LEN * sizeof(char));
                    call_some_function(buf);
                    free(buf);
     

    Remember to free any malloc space explicitly. This class could perhaps contain a finalize method that does the free, but note that in Java you should not use finalizers to free resources.

    See Also:
    CPtr
    • Field Summary

      • Fields inherited from class com.jstatcom.engine.CPtr

        NULL, SIZE
    • Constructor Summary

      Constructors 
      Constructor and Description
      CMalloc(int size)
      Allocate space in the C heap via a call to C's malloc.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      void copyIn(int bOff, byte[] buf, int index, int length)
      Indirect the C pointer to malloc space, a la CPtr.copyIn.
      void copyIn(int bOff, char[] buf, int index, int length)
      Indirect the C pointer to malloc space, a la CPtr.copyIn.
      void copyIn(int bOff, double[] buf, int index, int length)
      Indirect the C pointer to malloc space, a la CPtr.copyIn.
      void copyIn(int bOff, float[] buf, int index, int length)
      Indirect the C pointer to malloc space, a la CPtr.copyIn.
      void copyIn(int bOff, int[] buf, int index, int length)
      Indirect the C pointer to malloc space, a la CPtr.copyIn.
      void copyIn(int bOff, long[] buf, int index, int length)
      Indirect the C pointer to malloc space, a la CPtr.copyIn.
      void copyIn(int bOff, short[] buf, int index, int length)
      Indirect the C pointer to malloc space, a la CPtr.copyIn.
      void copyOut(int bOff, byte[] buf, int index, int length)
      Indirect the C pointer to malloc space, a la CPtr.copyOut.
      void copyOut(int bOff, char[] buf, int index, int length)
      Indirect the C pointer to malloc space, a la CPtr.copyOut.
      void copyOut(int bOff, double[] buf, int index, int length)
      Indirect the C pointer to malloc space, a la CPtr.copyOut.
      void copyOut(int bOff, float[] buf, int index, int length)
      Indirect the C pointer to malloc space, a la CPtr.copyOut.
      void copyOut(int bOff, int[] buf, int index, int length)
      Indirect the C pointer to malloc space, a la CPtr.copyOut.
      void copyOut(int bOff, long[] buf, int index, int length)
      Indirect the C pointer to malloc space, a la CPtr.copyOut.
      void copyOut(int bOff, short[] buf, int index, int length)
      Indirect the C pointer to malloc space, a la CPtr.copyOut.
      void free()
      De-allocate space obtained via an earlier call to malloc.
      byte getByte(int offset)
      Indirect the C pointer to malloc space, a la CPtr.getByte.
      CPtr getCPtr(int offset)
      Indirect the C pointer to malloc space, a la CPtr.getCPtr.
      double getDouble(int offset)
      Indirect the C pointer to malloc space, a la CPtr.getDouble.
      float getFloat(int offset)
      Indirect the C pointer to malloc space, a la CPtr.getFloat.
      int getInt(int offset)
      Indirect the C pointer to malloc space, a la CPtr.getInt.
      long getLong(int offset)
      Indirect the C pointer to malloc space, a la CPtr.getLong.
      short getShort(int offset)
      Indirect the C pointer to malloc space, a la CPtr.getShort.
      java.lang.String getString(int offset)
      Indirect the C pointer to malloc space, a la CPtr.getString.
      void setByte(int offset, byte value)
      Indirect the C pointer to malloc space, a la CPtr.setByte.
      void setCPtr(int offset, CPtr value)
      Indirect the C pointer to malloc space, a la CPtr.setCPtr.
      void setDouble(int offset, double value)
      Indirect the C pointer to malloc space, a la CPtr.setDouble.
      void setFloat(int offset, float value)
      Indirect the C pointer to malloc space, a la CPtr.setFloat.
      void setInt(int offset, int value)
      Indirect the C pointer to malloc space, a la CPtr.setInt.
      void setLong(int offset, long value)
      Indirect the C pointer to malloc space, a la CPtr.setLong.
      void setShort(int offset, short value)
      Indirect the C pointer to malloc space, a la CPtr.setShort.
      void setString(int offset, java.lang.String value)
      Indirect the C pointer to malloc space, a la CPtr.setString.
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CMalloc

        public CMalloc(int size)
        Allocate space in the C heap via a call to C's malloc.
        Parameters:
        size - number of bytes of space to allocate
    • Method Detail

      • free

        public void free()
        De-allocate space obtained via an earlier call to malloc.
      • copyIn

        public void copyIn(int bOff,
                           byte[] buf,
                           int index,
                           int length)
        Indirect the C pointer to malloc space, a la CPtr.copyIn. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
        Overrides:
        copyIn in class CPtr
        Parameters:
        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
        See Also:
        CPtr.copyIn(int,byte[],int,int)
      • copyIn

        public void copyIn(int bOff,
                           short[] buf,
                           int index,
                           int length)
        Indirect the C pointer to malloc space, a la CPtr.copyIn. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
        Overrides:
        copyIn in class CPtr
        Parameters:
        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
        See Also:
        CPtr.copyIn(int,short[],int,int)
      • copyIn

        public void copyIn(int bOff,
                           char[] buf,
                           int index,
                           int length)
        Indirect the C pointer to malloc space, a la CPtr.copyIn. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
        Overrides:
        copyIn in class CPtr
        Parameters:
        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
        See Also:
        CPtr.copyIn(int,char[],int,int)
      • copyIn

        public void copyIn(int bOff,
                           int[] buf,
                           int index,
                           int length)
        Indirect the C pointer to malloc space, a la CPtr.copyIn. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
        Overrides:
        copyIn in class CPtr
        Parameters:
        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
        See Also:
        CPtr.copyIn(int,int[],int,int)
      • copyIn

        public void copyIn(int bOff,
                           long[] buf,
                           int index,
                           int length)
        Indirect the C pointer to malloc space, a la CPtr.copyIn. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
        Overrides:
        copyIn in class CPtr
        Parameters:
        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
        See Also:
        CPtr.copyIn(int,long[],int,int)
      • copyIn

        public void copyIn(int bOff,
                           float[] buf,
                           int index,
                           int length)
        Indirect the C pointer to malloc space, a la CPtr.copyIn. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
        Overrides:
        copyIn in class CPtr
        Parameters:
        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
        See Also:
        CPtr.copyIn(int,float[],int,int)
      • copyIn

        public void copyIn(int bOff,
                           double[] buf,
                           int index,
                           int length)
        Indirect the C pointer to malloc space, a la CPtr.copyIn. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
        Overrides:
        copyIn in class CPtr
        Parameters:
        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
        See Also:
        CPtr.copyIn(int,double[],int,int)
      • copyOut

        public void copyOut(int bOff,
                            byte[] buf,
                            int index,
                            int length)
        Indirect the C pointer to malloc space, a la CPtr.copyOut. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
        Overrides:
        copyOut in class CPtr
        Parameters:
        bOff - byte offset from pointer into which data is copied
        buf - byte array into which data is copied
        index - array index from which to start copying
        length - number of elements from C pointer that must be copied
        See Also:
        CPtr.copyOut(int,byte[],int,int)
      • copyOut

        public void copyOut(int bOff,
                            short[] buf,
                            int index,
                            int length)
        Indirect the C pointer to malloc space, a la CPtr.copyOut. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
        Overrides:
        copyOut in class CPtr
        Parameters:
        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 C pointer that must be copied
        See Also:
        CPtr.copyOut(int,short[],int,int)
      • copyOut

        public void copyOut(int bOff,
                            char[] buf,
                            int index,
                            int length)
        Indirect the C pointer to malloc space, a la CPtr.copyOut. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
        Overrides:
        copyOut in class CPtr
        Parameters:
        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 C pointer that must be copied
        See Also:
        CPtr.copyOut(int,char[],int,int)
      • copyOut

        public void copyOut(int bOff,
                            int[] buf,
                            int index,
                            int length)
        Indirect the C pointer to malloc space, a la CPtr.copyOut. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
        Overrides:
        copyOut in class CPtr
        Parameters:
        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 C pointer that must be copied
        See Also:
        CPtr.copyOut(int,int[],int,int)
      • copyOut

        public void copyOut(int bOff,
                            long[] buf,
                            int index,
                            int length)
        Indirect the C pointer to malloc space, a la CPtr.copyOut. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
        Overrides:
        copyOut in class CPtr
        Parameters:
        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 C pointer that must be copied
        See Also:
        CPtr.copyOut(int,long[],int,int)
      • copyOut

        public void copyOut(int bOff,
                            float[] buf,
                            int index,
                            int length)
        Indirect the C pointer to malloc space, a la CPtr.copyOut. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
        Overrides:
        copyOut in class CPtr
        Parameters:
        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 C pointer that must be copied
        See Also:
        CPtr.copyOut(int,float[],int,int)
      • copyOut

        public void copyOut(int bOff,
                            double[] buf,
                            int index,
                            int length)
        Indirect the C pointer to malloc space, a la CPtr.copyOut. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
        Overrides:
        copyOut in class CPtr
        Parameters:
        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 C pointer that must be copied
        See Also:
        CPtr.copyOut(int,double[],int,int)
      • getByte

        public byte getByte(int offset)
        Indirect the C pointer to malloc space, a la CPtr.getByte. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
        Overrides:
        getByte in class CPtr
        Parameters:
        offset - offset from pointer to perform the indirection
        Returns:
        the byte value being pointed to
        See Also:
        CPtr.getByte(int)
      • getShort

        public short getShort(int offset)
        Indirect the C pointer to malloc space, a la CPtr.getShort. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
        Overrides:
        getShort in class CPtr
        Parameters:
        offset - byte offset from pointer to perform the indirection
        Returns:
        the short value being pointed to
        See Also:
        CPtr.getShort(int)
      • getInt

        public int getInt(int offset)
        Indirect the C pointer to malloc space, a la CPtr.getInt. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
        Overrides:
        getInt in class CPtr
        Parameters:
        offset - byte offset from pointer to perform the indirection
        Returns:
        the int value being pointed to
        See Also:
        CPtr.getInt(int)
      • getLong

        public long getLong(int offset)
        Indirect the C pointer to malloc space, a la CPtr.getLong. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
        Overrides:
        getLong in class CPtr
        Parameters:
        offset - byte offset from pointer to perform the indirection
        Returns:
        the long value being pointed to
        See Also:
        CPtr.getLong(int)
      • getFloat

        public float getFloat(int offset)
        Indirect the C pointer to malloc space, a la CPtr.getFloat. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
        Overrides:
        getFloat in class CPtr
        Parameters:
        offset - byte offset from pointer to perform the indirection
        Returns:
        the float value being pointed to
        See Also:
        CPtr.getFloat(int)
      • getDouble

        public double getDouble(int offset)
        Indirect the C pointer to malloc space, a la CPtr.getDouble. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
        Overrides:
        getDouble in class CPtr
        Parameters:
        offset - byte offset from pointer to perform the indirection
        Returns:
        the double value being pointed to
        See Also:
        CPtr.getDouble(int)
      • getCPtr

        public CPtr getCPtr(int offset)
        Indirect the C pointer to malloc space, a la CPtr.getCPtr. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
        Overrides:
        getCPtr in class CPtr
        Parameters:
        offset - byte offset from pointer to perform the indirection
        Returns:
        the pointer value being pointed to
        See Also:
        CPtr.getCPtr(int)
      • getString

        public java.lang.String getString(int offset)
        Indirect the C pointer to malloc space, a la CPtr.getString. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
        Overrides:
        getString in class CPtr
        Parameters:
        offset - byte offset from pointer to obtain the C string
        Returns:
        the String value being pointed to
        See Also:
        CPtr.getString(int)
      • setByte

        public void setByte(int offset,
                            byte value)
        Indirect the C pointer to malloc space, a la CPtr.setByte. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
        Overrides:
        setByte in class CPtr
        Parameters:
        offset - byte offset from pointer at which value must be set
        value - byte value to set
        See Also:
        CPtr.setByte(int, byte)
      • setShort

        public void setShort(int offset,
                             short value)
        Indirect the C pointer to malloc space, a la CPtr.setShort. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
        Overrides:
        setShort in class CPtr
        Parameters:
        offset - byte offset from pointer at which value must be set
        value - short value to set
        See Also:
        CPtr.setShort(int, short)
      • setInt

        public void setInt(int offset,
                           int value)
        Indirect the C pointer to malloc space, a la CPtr.setInt. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
        Overrides:
        setInt in class CPtr
        Parameters:
        offset - byte offset from pointer at which value must be set
        value - int value to set
        See Also:
        CPtr.setInt(int, int)
      • setLong

        public void setLong(int offset,
                            long value)
        Indirect the C pointer to malloc space, a la CPtr.setLong. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
        Overrides:
        setLong in class CPtr
        Parameters:
        offset - byte offset from pointer at which value must be set
        value - long value to set
        See Also:
        CPtr.setLong(int, long)
      • setFloat

        public void setFloat(int offset,
                             float value)
        Indirect the C pointer to malloc space, a la CPtr.setFloat. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
        Overrides:
        setFloat in class CPtr
        Parameters:
        offset - byte offset from pointer at which value must be set
        value - float value to set
        See Also:
        CPtr.setFloat(int, float)
      • setDouble

        public void setDouble(int offset,
                              double value)
        Indirect the C pointer to malloc space, a la CPtr.setDouble. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
        Overrides:
        setDouble in class CPtr
        Parameters:
        offset - byte offset from pointer at which value must be set
        value - double value to set
        See Also:
        CPtr.setDouble(int, double)
      • setCPtr

        public void setCPtr(int offset,
                            CPtr value)
        Indirect the C pointer to malloc space, a la CPtr.setCPtr. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
        Overrides:
        setCPtr in class CPtr
        Parameters:
        offset - byte offset from pointer at which value must be set
        value - CPtr value to set
        See Also:
        CPtr.setCPtr(int, com.jstatcom.engine.CPtr)
      • setString

        public void setString(int offset,
                              java.lang.String value)
        Indirect the C pointer to malloc space, a la CPtr.setString. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
        Overrides:
        setString in class CPtr
        Parameters:
        offset - byte offset from pointer at which characters in value must be set
        value - String value to set
        See Also:
        CPtr.setString(int, java.lang.String)

DMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.