Class CMalloc

java.lang.Object
  |
  +--CPointer
        |
        +--CMalloc

public class CMalloc
extends CPointer

A CPointer 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.

Author:
Sheng Liang
See Also:
CPointer

Fields inherited from class CPointer
peer, SIZE
 
Constructor Summary
CMalloc(int size)
          Allocate space in the C heap via a call to C's malloc.
 
Method Summary
 void copyIn(int bOff, byte[] buf, int index, int length)
          Indirect the C pointer to malloc space, a la CPointer.copyIn.
 void copyIn(int bOff, char[] buf, int index, int length)
          Indirect the C pointer to malloc space, a la CPointer.copyIn.
 void copyIn(int bOff, double[] buf, int index, int length)
          Indirect the C pointer to malloc space, a la CPointer.copyIn.
 void copyIn(int bOff, float[] buf, int index, int length)
          Indirect the C pointer to malloc space, a la CPointer.copyIn.
 void copyIn(int bOff, int[] buf, int index, int length)
          Indirect the C pointer to malloc space, a la CPointer.copyIn.
 void copyIn(int bOff, long[] buf, int index, int length)
          Indirect the C pointer to malloc space, a la CPointer.copyIn.
 void copyIn(int bOff, short[] buf, int index, int length)
          Indirect the C pointer to malloc space, a la CPointer.copyIn.
 void copyOut(int bOff, byte[] buf, int index, int length)
          Indirect the C pointer to malloc space, a la CPointer.copyOut.
 void copyOut(int bOff, char[] buf, int index, int length)
          Indirect the C pointer to malloc space, a la CPointer.copyOut.
 void copyOut(int bOff, double[] buf, int index, int length)
          Indirect the C pointer to malloc space, a la CPointer.copyOut.
 void copyOut(int bOff, float[] buf, int index, int length)
          Indirect the C pointer to malloc space, a la CPointer.copyOut.
 void copyOut(int bOff, int[] buf, int index, int length)
          Indirect the C pointer to malloc space, a la CPointer.copyOut.
 void copyOut(int bOff, long[] buf, int index, int length)
          Indirect the C pointer to malloc space, a la CPointer.copyOut.
 void copyOut(int bOff, short[] buf, int index, int length)
          Indirect the C pointer to malloc space, a la CPointer.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 CPointer.getByte.
 CPointer getCPointer(int offset)
          Indirect the C pointer to malloc space, a la CPointer.getCPointer.
 double getDouble(int offset)
          Indirect the C pointer to malloc space, a la CPointer.getDouble.
 float getFloat(int offset)
          Indirect the C pointer to malloc space, a la CPointer.getFloat.
 int getInt(int offset)
          Indirect the C pointer to malloc space, a la CPointer.getInt.
 long getLong(int offset)
          Indirect the C pointer to malloc space, a la CPointer.getLong.
 short getShort(int offset)
          Indirect the C pointer to malloc space, a la CPointer.getShort.
 java.lang.String getString(int offset)
          Indirect the C pointer to malloc space, a la CPointer.getString.
 void setByte(int offset, byte value)
          Indirect the C pointer to malloc space, a la CPointer.setByte.
 void setCPointer(int offset, CPointer value)
          Indirect the C pointer to malloc space, a la CPointer.setCPointer.
 void setDouble(int offset, double value)
          Indirect the C pointer to malloc space, a la CPointer.setDouble.
 void setFloat(int offset, float value)
          Indirect the C pointer to malloc space, a la CPointer.setFloat.
 void setInt(int offset, int value)
          Indirect the C pointer to malloc space, a la CPointer.setInt.
 void setLong(int offset, long value)
          Indirect the C pointer to malloc space, a la CPointer.setLong.
 void setShort(int offset, short value)
          Indirect the C pointer to malloc space, a la CPointer.setShort.
 void setString(int offset, java.lang.String value)
          Indirect the C pointer to malloc space, a la CPointer.setString.
 
Methods inherited from class CPointer
equals, hashCode
 
Methods inherited from class java.lang.Object
clone, finalize, 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 CPointer.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 CPointer
See Also:
CPointer.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 CPointer.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 CPointer
See Also:
CPointer.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 CPointer.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 CPointer
See Also:
CPointer.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 CPointer.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 CPointer
See Also:
CPointer.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 CPointer.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 CPointer
See Also:
CPointer.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 CPointer.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 CPointer
See Also:
CPointer.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 CPointer.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 CPointer
See Also:
CPointer.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 CPointer.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 CPointer
See Also:
CPointer.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 CPointer.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 CPointer
See Also:
CPointer.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 CPointer.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 CPointer
See Also:
CPointer.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 CPointer.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 CPointer
See Also:
CPointer.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 CPointer.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 CPointer
See Also:
CPointer.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 CPointer.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 CPointer
See Also:
CPointer.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 CPointer.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 CPointer
See Also:
CPointer.copyOut(int,double[],int,int)

getByte

public byte getByte(int offset)
Indirect the C pointer to malloc space, a la CPointer.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 CPointer
See Also:
CPointer.getByte(int)

getShort

public short getShort(int offset)
Indirect the C pointer to malloc space, a la CPointer.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 CPointer
See Also:
CPointer.getShort(int)

getInt

public int getInt(int offset)
Indirect the C pointer to malloc space, a la CPointer.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 CPointer
See Also:
CPointer.getInt(int)

getLong

public long getLong(int offset)
Indirect the C pointer to malloc space, a la CPointer.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 CPointer
See Also:
CPointer.getLong(int)

getFloat

public float getFloat(int offset)
Indirect the C pointer to malloc space, a la CPointer.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 CPointer
See Also:
CPointer.getFloat(int)

getDouble

public double getDouble(int offset)
Indirect the C pointer to malloc space, a la CPointer.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 CPointer
See Also:
CPointer.getDouble(int)

getCPointer

public CPointer getCPointer(int offset)
Indirect the C pointer to malloc space, a la CPointer.getCPointer. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
Overrides:
getCPointer in class CPointer
See Also:
CPointer.getCPointer(int)

getString

public java.lang.String getString(int offset)
Indirect the C pointer to malloc space, a la CPointer.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 CPointer
See Also:
CPointer.getString(int)

setByte

public void setByte(int offset,
                    byte value)
Indirect the C pointer to malloc space, a la CPointer.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 CPointer
See Also:
CPointer.setByte(int, byte)

setShort

public void setShort(int offset,
                     short value)
Indirect the C pointer to malloc space, a la CPointer.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 CPointer
See Also:
CPointer.setShort(int, short)

setInt

public void setInt(int offset,
                   int value)
Indirect the C pointer to malloc space, a la CPointer.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 CPointer
See Also:
CPointer.setInt(int, int)

setLong

public void setLong(int offset,
                    long value)
Indirect the C pointer to malloc space, a la CPointer.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 CPointer
See Also:
CPointer.setLong(int, long)

setFloat

public void setFloat(int offset,
                     float value)
Indirect the C pointer to malloc space, a la CPointer.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 CPointer
See Also:
CPointer.setFloat(int, float)

setDouble

public void setDouble(int offset,
                      double value)
Indirect the C pointer to malloc space, a la CPointer.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 CPointer
See Also:
CPointer.setDouble(int, double)

setCPointer

public void setCPointer(int offset,
                        CPointer value)
Indirect the C pointer to malloc space, a la CPointer.setCPointer. But this method performs a bounds checks to ensure that the indirection does not cause memory outside the malloced space to be accessed.
Overrides:
setCPointer in class CPointer
See Also:
CPointer.setCPointer(int, CPointer)

setString

public void setString(int offset,
                      java.lang.String value)
Indirect the C pointer to malloc space, a la CPointer.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 CPointer
See Also:
CPointer.setString(int, String)