add bulk memory operations and memtest
[tedtools.git] / tmalloc.h
index 0c3a275..fce5dba 100644 (file)
--- a/tmalloc.h
+++ b/tmalloc.h
@@ -42,4 +42,51 @@ char * tnstrdup(char *src, int len);
 char * strlower(char * src);
 char * strupper(char * src);
 int clrspace(char *buf);
+
+/* fast allocate */
+
+#define CNTXCHUNK      (1024*1024)
+
+typedef struct MemoryChunk {
+       size_t  size;
+       size_t  freesize;
+       struct MemoryChunk      *next;
+       char data[1];
+} MemoryChunk;
+
+#define MEMCHNKHDRSZ   ( sizeof(u_int32_t)*2 + sizeof(MemoryChunk*) )
+
+typedef struct MemoryContext {
+       u_int32_t       flags;
+       struct MemoryContext    *parent;
+       struct MemoryContext    *child;
+       MemoryChunk     *chunk;
+} MemoryContext;
+
+#define MC_DEBUG       0x01    
+
+typedef struct {
+       size_t  size;
+       MemoryContext   *cntx;
+       char    data[1];        
+} MCAllocatedSpace;
+
+#define MCASHDRSZ ( sizeof(size_t) + sizeof(MemoryContext*) )
+#define MCMAGICKNUMBER (0xFE0FBEEF)
+
+#define TYPEALIGN(ALIGNVAL,LEN)  \
+        (((long) (LEN) + (ALIGNVAL-1)) & ~((long) (ALIGNVAL-1)))
+
+#define PTRALIGN(LEN)     TYPEALIGN(sizeof(void*), (LEN))
+
+MemoryContext *allocMemoryContext(MemoryContext* parent, int flags);
+void freeMemoryContext(MemoryContext* cntx);
+void*   mcalloc(MemoryContext *cntx, size_t size);
+void*   mc0alloc(MemoryContext *cntx, size_t size);
+void*   mcrealloc(void * ptr, size_t size);
+void   mcfree(void * ptr);
+char * mcstrdup(MemoryContext *cntx, char * src);
+char * mcnstrdup(MemoryContext *cntx, char *src, int len);
+
+
 #endif