}
}
+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;
chunk = newchunk;
}
- chunk->freesize -= size;
- alloc = (MCAllocatedSpace*)( chunk->data + chunk->freesize );
+ alloc = (MCAllocatedSpace*)( chunk->data + chunk->size - chunk->freesize );
alloc->size = size;
alloc->cntx = cntx;
+ chunk->freesize -= size;
if ( cntx->flags & MC_DEBUG ) {
*(u_int32_t*)((char*)alloc + alloc->size - sizeof(u_int32_t) ) = MCMAGICKNUMBER;
realsize = alloc->size - MCASHDRSZ;
if ( size > realsize ) {
- if ( (char*)alloc == alloc->cntx->chunk->data + alloc->cntx->chunk->freesize &&
+ MemoryChunk *chunk = alloc->cntx->chunk;
+ if ( (char*)alloc == chunk->data + chunk->size - chunk->freesize - alloc->size &&
PTRALIGN(size)-realsize <= alloc->cntx->chunk->freesize ) {
/* just enlarge */
alloc->cntx->chunk->freesize -= PTRALIGN(size)-realsize;
void
mcfree(void * ptr) {
MCAllocatedSpace *alloc = (MCAllocatedSpace*)( (char*)ptr - MCASHDRSZ );
+ MemoryChunk *chunk;
if ( ptr==NULL )
tlog(TL_CRIT|TL_EXIT, "mcfree: free null pointer");
if ( alloc->cntx->flags & MC_DEBUG )
tassert( *(u_int32_t*)((char*)alloc + alloc->size - sizeof(u_int32_t) ) == MCMAGICKNUMBER );
- if ( (char*)alloc == alloc->cntx->chunk->data + alloc->cntx->chunk->freesize ) /* last allocated value */
+ chunk = alloc->cntx->chunk;
+ if ( (char*)alloc == chunk->data + chunk->size - chunk->freesize - alloc->size ) /* last allocated value */
alloc->cntx->chunk->freesize+=alloc->size;
alloc->cntx=NULL;