Contents | Package | Class | Tree | Deprecated | Index | Help
PREV | NEXT SHOW LISTS | HIDE LISTS

Class CMalloc

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

public 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.

Author:
Sheng Liang
See Also:
CPtr

Fields inherited from class CPtr
 NULL, 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 CPtr.copyIn.
void  copyIn(int bOff, short[] 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, 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, float[] 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  copyOut(int bOff, byte[] 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  copyOut(int bOff, char[] 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, float[] 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  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 CPtr
 copyIn, copyIn, copyIn, copyIn, copyIn, copyIn, copyIn, copyOut, copyOut, copyOut, copyOut, copyOut, copyOut, copyOut, equals, getByte, getCPtr, getDouble, getFloat, getInt, getLong, getShort, getString, hashCode, setByte, setCPtr, setDouble, setFloat, setInt, setLong, setShort, setString
 
Methods inherited from class java.lang.Object
 clone, equals, finalize, getClass, hashCode, 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
See Also:
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
See Also:
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
See Also:
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
See Also:
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
See Also:
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
See Also:
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
See Also:
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
See Also:
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
See Also:
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
See Also:
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
See Also:
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
See Also:
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
See Also:
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
See Also:
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
See Also:
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
See Also:
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
See Also:
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
See Also:
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
See Also:
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
See Also:
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
See Also:
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
See Also:
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
See Also:
setByte(int)

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
See Also:
setShort(int)

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
See Also:
setInt(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
See Also:
setLong(int)

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
See Also:
setFloat(int)

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
See Also:
setDouble(int)

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
See Also:
setCPtr(int)

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
See Also:
setString(int)

Contents | Package | Class | Tree | Deprecated | Index | Help
PREV | NEXT SHOW LISTS | HIDE LISTS