model view prototype
[convexer.git] / cxr / cxr_mem.h
index 437831489ce2c741a810b00401730467abf9b38d..38e7a3f1bd7a1d4cff8d88f14da6e9dbc226614c 100644 (file)
@@ -1,3 +1,12 @@
+#ifndef CXR_MEM_H
+#define CXR_MEM_H
+
+#include <string.h>
+#include <stdlib.h>
+
+#include "cxr_types.h"
+#include "cxr_math.h"
+
 typedef struct cxr_abuffer cxr_abuffer;
 
 struct cxr_abuffer
@@ -28,7 +37,8 @@ static void *__cxr_ab_ptr( struct cxr_abuffer *buffer, u32 index
 #ifdef CXR_DEBUG_ALLOCATORS
    if( index >= buffer->capacity || index < 0 )
    {
-      printf( "index out of capactity (%d /: [0->%d (cap)]) (%s)\n", index, buffer->capacity, debug_str );
+      printf( "index out of capactity (%d /: [0->%d (cap)]) (%s)\n", index, 
+            buffer->capacity, debug_str );
       exit(1);
    }
 #endif
@@ -84,10 +94,13 @@ static void cxr_ab_push( struct cxr_abuffer *buffer, void *em )
 static void cxr_ab_init( struct cxr_abuffer *buffer, u32 esize, u32 cap )
 {
    buffer->esize = esize;
-   buffer->capacity = cxr_max(1,cap);
+   buffer->capacity = cap;
    buffer->count = 0;
 
-   buffer->arr = malloc( buffer->esize*buffer->capacity );
+   if( cap )
+      buffer->arr = malloc( buffer->esize*buffer->capacity );
+   else
+      buffer->arr = NULL;
 }
 
 static void cxr_ab_clear( struct cxr_abuffer *buffer )
@@ -99,3 +112,5 @@ static void cxr_ab_free( struct cxr_abuffer *buffer )
 {
    free( buffer->arr );
 }
+
+#endif /* CXR_TYPES_H */