+#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
#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
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 )
{
free( buffer->arr );
}
+
+#endif /* CXR_TYPES_H */