Add resetMemoryContext()
[tedtools.git] / tmalloc.c
index 9f96ab9..c03a7ff 100644 (file)
--- a/tmalloc.c
+++ b/tmalloc.c
@@ -161,6 +161,25 @@ freeMemoryContext(MemoryContext *cntx) {
        }
 }
 
+void
+resetMemoryContext(MemoryContext *cntx) {
+       MemoryChunk *chunk, *chunkptr;
+
+       while( cntx ) {
+               chunkptr = cntx->chunk;
+               chunkptr->freesize = chunkptr->size;
+               chunkptr = chunkptr->next;
+               cntx->chunk->next = NULL;
+
+               while( chunkptr ) {
+                       chunk=chunkptr->next;
+                       tfree(chunkptr);
+                       chunkptr=chunk;
+               }
+               cntx=cntx->child;
+       }
+}
+
 void*   
 mcalloc(MemoryContext *cntx, size_t size) {
        MemoryChunk     *chunk = cntx->chunk;