X-Git-Url: https://harrygodden.com/git/?p=convexer.git;a=blobdiff_plain;f=cxr%2Fcxr_mem.h;fp=cxr%2Fcxr_mem.h;h=38e7a3f1bd7a1d4cff8d88f14da6e9dbc226614c;hp=437831489ce2c741a810b00401730467abf9b38d;hb=dbd379f76bcb2139fdb5740232511fa789018e10;hpb=8e1b6889db7ce10f8d594539ef74dc4390e8e891 diff --git a/cxr/cxr_mem.h b/cxr/cxr_mem.h index 4378314..38e7a3f 100644 --- a/cxr/cxr_mem.h +++ b/cxr/cxr_mem.h @@ -1,3 +1,12 @@ +#ifndef CXR_MEM_H +#define CXR_MEM_H + +#include +#include + +#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 */