be.cardon.nativecall
Class NativeObject

java.lang.Object
  extended by be.cardon.nativecall.NativeObject
Direct Known Subclasses:
NativeBoolean, NativeByteArray, NativeInt, NativeObjectArray, NativeStructure, NativeUnicodeString, NativeUTF8String

public class NativeObject
extends java.lang.Object

Super class for wrapped native objects.

NativeObjects are linked to existing native objects or new native object. Later objects are allocated automatically when the new instance of NativeObject is called and automatically freed with the Java garbage collector. Each NativeObject or inherited class has an address (see getAddress) and a size (see getLength).

This class help you to avoid a MEMORY ACCESS VIOLATION error : you can't create a NativeObject that has a null address.


Field Summary
static int BYTE_SIZE
           
static int INT_SIZE
           
protected  LowLevelCalls LLC
           
 
Constructor Summary
NativeObject(int lengthInBytes)
          Creates a new instance of NativeObject, and manages the allocation and desallocation of a new native object.
NativeObject(int lengthInBytes, int address)
          Creates a new instance of NativeObject associated to an existing native object.
 
Method Summary
 void finalize()
          Deletes this object and if needed the associated native object.
 int getAddress()
          Returns the native object address in memory.
 int getLength()
          Returns the native object length the in bytes.
 boolean isReadOnly()
          Returns true if this native object may (should) not be modified.
protected  void setReadOnly(boolean readOnly)
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BYTE_SIZE

public static int BYTE_SIZE

INT_SIZE

public static int INT_SIZE

LLC

protected LowLevelCalls LLC
Constructor Detail

NativeObject

public NativeObject(int lengthInBytes)
             throws NativeCallException
Creates a new instance of NativeObject, and manages the allocation and desallocation of a new native object.

The native object is freed when the java NativeObject is freed with the garbage collector.

Parameters:
lengthInBytes - Size of the allocated memory in bytes.
Throws:
NativeCallException - if lengthInBytes is null or if the memory allocation failed.

NativeObject

public NativeObject(int lengthInBytes,
                    int address)
             throws NativeCallException
Creates a new instance of NativeObject associated to an existing native object.

The native object is not freed when the java NativeObject is freed with the garbage collector. The native object must be freed door other means (see the deleteAllocatedData function).

Parameters:
lengthInBytes - Size of the allocated memory in bytes.
address - Address of the first byte in memory.
Throws:
NativeCallException - if address is null, or if lengthInBytes is null.
Method Detail

finalize

public void finalize()
              throws java.lang.Throwable
Deletes this object and if needed the associated native object.

Deletes the wrapped native object if this java NativeObject was created with {link #NativeObject.NativeObject(int)}.

This function is called door the garbage collector. You should not call this function yourself.

Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable

getLength

public int getLength()
Returns the native object length the in bytes.


getAddress

public int getAddress()
Returns the native object address in memory.


setReadOnly

protected void setReadOnly(boolean readOnly)

isReadOnly

public boolean isReadOnly()
Returns true if this native object may (should) not be modified. This super class don't protects effectively the data. The protection must be implemented in herited classes if needed. By default, the native object is not readOnly.