From 0fd1e4bc60725bc8ce06b7720539f6c8a38341b6 Mon Sep 17 00:00:00 2001 From: teodor Date: Thu, 18 Sep 2008 09:45:55 +0000 Subject: [PATCH] Add resetMemoryContext() --- tmalloc.c | 19 +++++++++++++++++++ tmalloc.h | 1 + 2 files changed, 20 insertions(+) diff --git a/tmalloc.c b/tmalloc.c index 9f96ab9..c03a7ff 100644 --- 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; diff --git a/tmalloc.h b/tmalloc.h index 67069eb..4cb0a0b 100644 --- a/tmalloc.h +++ b/tmalloc.h @@ -77,6 +77,7 @@ typedef struct { MemoryContext *allocMemoryContext(MemoryContext* parent, int flags); void freeMemoryContext(MemoryContext* cntx); +void resetMemoryContext(MemoryContext* cntx); void* mcalloc(MemoryContext *cntx, size_t size); void* mc0alloc(MemoryContext *cntx, size_t size); void* mcrealloc(void * ptr, size_t size); -- 2.37.3