aboutsummaryrefslogtreecommitdiffstats
path: root/CNativeCode
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2002-04-17 19:08:37 +0000
committerSven Gothel <[email protected]>2002-04-17 19:08:37 +0000
commit6114297dac0848d470a3211915bea64f49d584e7 (patch)
tree106702477036d454aa01242f5b7fdf060b8eaa42 /CNativeCode
parent4c7204560056fe3bb0289c64020cbb9df17a757b (diff)
completes pepijn's GC patch (missed to add them to the repository)
Diffstat (limited to 'CNativeCode')
-rw-r--r--CNativeCode/MemoryManager.c79
-rw-r--r--CNativeCode/MemoryManager.h25
2 files changed, 104 insertions, 0 deletions
diff --git a/CNativeCode/MemoryManager.c b/CNativeCode/MemoryManager.c
new file mode 100644
index 0000000..ed2f596
--- /dev/null
+++ b/CNativeCode/MemoryManager.c
@@ -0,0 +1,79 @@
+#include "MemoryManager.h"
+
+ArrayList *tesselator_list[NUMBER_OF_LISTS];
+
+void RegisterArray(JNIEnv *env, void *java_array, void *native_array,
+ JavaBasicType array_type, ListType ltype)
+{
+ ArrayList *new_element = NULL;
+
+ if ( 0<= ltype && ltype < NUMBER_OF_LISTS &&
+ T_BOOLEAN_ARRAY <= array_type && array_type <= T_DOUBLE_ARRAY
+ )
+ {
+ new_element = malloc(sizeof(ArrayList));
+ new_element->java_array = java_array;
+ new_element->native_array = native_array;
+ new_element->type = array_type;
+ new_element->next = tesselator_list[ltype];
+ tesselator_list[ltype] = new_element;
+ return;
+ }
+ jnitoolsThrowByName(env, "java/lang/IllegalArgumentException",
+ "RegisterArray of JavaBasicType %d and ListType %d failed",
+ array_type, ltype);
+}
+
+void FreeArrays(JNIEnv *env, ListType ltype)
+{
+ ArrayList *element = NULL;
+ ArrayList *next = NULL;
+
+ if (ltype >= 0 && ltype < NUMBER_OF_LISTS)
+ {
+ element = tesselator_list[ltype];
+ while (element != 0)
+ {
+ next = element->next;
+ switch (element->type)
+ {
+ case T_BOOLEAN_ARRAY:
+ (*env)->ReleaseBooleanArrayElements(env, element->java_array, element->native_array, JNI_ABORT);
+ break;
+ case T_BYTE_ARRAY:
+ (*env)->ReleaseByteArrayElements(env, element->java_array, element->native_array, JNI_ABORT);
+ break;
+ case T_CHAR_ARRAY:
+ (*env)->ReleaseCharArrayElements(env, element->java_array, element->native_array, JNI_ABORT);
+ break;
+ case T_SHORT_ARRAY:
+ (*env)->ReleaseShortArrayElements(env, element->java_array, element->native_array, JNI_ABORT);
+ break;
+ case T_INT_ARRAY:
+ (*env)->ReleaseIntArrayElements(env, element->java_array, element->native_array, JNI_ABORT);
+ break;
+ case T_LONG_ARRAY:
+ (*env)->ReleaseLongArrayElements(env, element->java_array, element->native_array, JNI_ABORT);
+ break;
+ case T_FLOAT_ARRAY:
+ (*env)->ReleaseFloatArrayElements(env, element->java_array, element->native_array, JNI_ABORT);
+ break;
+ case T_DOUBLE_ARRAY:
+ (*env)->ReleaseDoubleArrayElements(env, element->java_array, element->native_array, JNI_ABORT);
+ break;
+ default:
+ jnitoolsThrowByName(env, "java/lang/IllegalArgumentException",
+ "FreeArrays of JavaBasicType %d failed",
+ element->type);
+ }
+ free(element);
+ element = next;
+ }
+ tesselator_list[ltype] = 0;
+ return;
+ }
+ jnitoolsThrowByName(env, "java/lang/IllegalArgumentException",
+ "RegisterArray of ListType %d failed",
+ ltype);
+}
+
diff --git a/CNativeCode/MemoryManager.h b/CNativeCode/MemoryManager.h
new file mode 100644
index 0000000..51271ce
--- /dev/null
+++ b/CNativeCode/MemoryManager.h
@@ -0,0 +1,25 @@
+#ifndef MEMORYMANAGER
+ #define MEMORYMANAGER
+
+ #include "jnitools.h"
+
+ typedef enum { MEMM_TESSELATOR,
+ MEMM_SELECTION,
+ MEMM_LAST
+ } ListType;
+
+ #define NUMBER_OF_LISTS ((int)MEMM_LAST)
+
+ typedef struct tnode {
+ void *java_array;
+ void *native_array;
+ JavaBasicType type;
+ void *next;
+ } ArrayList;
+
+ void RegisterArray(JNIEnv *env, void *java_array, void *native_array,
+ JavaBasicType array_type, ListType ltype);
+
+ void FreeArrays(JNIEnv *env, ListType ltype);
+
+#endif