Browse Source

Larson is now compiled only if HAVE_LOCKS is enabled, created a small test for memory-space aware allocators.

Ioannis Koutras 13 years ago
parent
commit
d72234fa01
2 changed files with 36 additions and 5 deletions
  1. 13 5
      examples/CMakeLists.txt
  2. 23 0
      examples/test_for_memory_space_aware.c

+ 13 - 5
examples/CMakeLists.txt

@@ -6,9 +6,17 @@ include_directories(
 
 
 set(CMAKE_BUILD_TYPE RelWithDebInfo)
 set(CMAKE_BUILD_TYPE RelWithDebInfo)
 
 
-add_executable(test test.c)
-target_link_libraries(test ${DMMLIB_SHARED_LIBRARY})
+if (HAVE_LOCKS)
+  find_package (Threads)
+  add_executable(larson larson.c)
+  target_link_libraries(larson ${DMMLIB_SHARED_LIBRARY} ${CMAKE_THREAD_LIBS_INIT})
+endif (HAVE_LOCKS)
+
+if (WITH_MEMORY_SPACE_AWARENESS)
+  add_executable(test_for_memory_space_aware test_for_memory_space_aware.c)
+  target_link_libraries(test_for_memory_space_aware ${DMMLIB_SHARED_LIBRARY})
+else (WITH_MEMORY_SPACE_AWARENESS)
+  add_executable(test test.c)
+  target_link_libraries(test ${DMMLIB_SHARED_LIBRARY})
+endif (WITH_MEMORY_SPACE_AWARENESS)
 
 
-find_package (Threads)
-add_executable(larson larson.c)
-target_link_libraries(larson ${DMMLIB_SHARED_LIBRARY} ${CMAKE_THREAD_LIBS_INIT})

+ 23 - 0
examples/test_for_memory_space_aware.c

@@ -0,0 +1,23 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <dmmlib/initialize_allocator.h>
+#include <dmmlib/dmmlib.h>
+
+#define ALLOCATOR_SIZE 16*1024*sizeof(char)
+
+int main(void) {
+
+    allocator_t systemallocator;
+    void *p1, *p2, *p3;
+    
+    initialize_allocator(&systemallocator, malloc(ALLOCATOR_SIZE), ALLOCATOR_SIZE);
+
+    p1 = custom_ahmalloc(&systemallocator, &systemallocator.heaps[0], (size_t) 1024);
+    custom_ahfree(&systemallocator, &systemallocator.heaps[0], p1);
+    p2 = custom_ahmalloc(&systemallocator, &systemallocator.heaps[0], (size_t) 512);
+    p3 = custom_ahmalloc(&systemallocator, &systemallocator.heaps[0], (size_t) 394);
+    custom_ahfree(&systemallocator, &systemallocator.heaps[0], p2);
+    custom_ahfree(&systemallocator, &systemallocator.heaps[0], p3);
+
+    return 0;
+}