From: "Todd" <todd@opencola.com>
Subject: FEC using the Java Native Interface
Date: Friday, March 30, 2001 10:22 AM

The implementation of FEC using JNI (in Swarmcast) hasn't changed since
Justin completed the code.
What HAS changed is how the JNI lets the JVM know about memory useage, and
this has been addressed in the following files <and check out the
explanation at the bottom of this posting>:
fec8-jinterf.c    - Linux
fec16-jinterf.c    - Linux
fec8_win32.c    - win32
fec16_win32.c    - win32

At the moment these files are identical. This means they compile on Linux
and Win32. However, I chose to leave them as seperate files in case of
future changes which may break that compatibility.

The Linux code is compiled with the makefile at the following location:
Swarmcast\FEC\src\csrc

The Windows code is compiled using MSVC++, using the workspace at the
following location:
Swarmcast\FEC\src\csrc\MSVC\FEC_dlls\FEC_dlls.dsw

The following 2 files determine the useage of the FEC JNI code in Swarmcast.
Swarmcast/FEC/classes/lib/fec.properties turns "on" the fec native jni code.
Swarmcast/FEC/classes/lib/native-lib.properties specifies the location of
the compiled c code.

The following files have additional information and help:
Swarmcast\FEC\src\csrc\MSVC\JNI_HOWTO
Swarmcast\FEC\src\csrc\MSVC\JNI_README
Swarmcast\FEC\src\csrc\MSVC\README


------------------------------------
The Java code uses JNI to call the native FEC C routines. It should be noted
that while Java passes parameters (using JNI) to the C-code, in fact the
parameters are accessed using the same memory space. (actually the JVM
decides...the programmer has no control over this.)
To ensure proper "clean up" after native code execution, surround the JNI
code with the following statements. This lets the Java garbage collector
know that the memory is free.

PushLocalFrame
<jni code>
PopLocalFrame

These JNI statements are implemented similarly to database transactions
"begin transaction" and "commit transaction".

As well,  if you use any malloc statements, don't forget to use free...
And if primitive data types are used, consider using the JNI statements
"PrimitiveArray..." etc. to ensure that types are used properly.









 