void smFreeBlocks(Structure_Manager *pSM) { void *pCurBlock, *pNextBlock; pCurBlock = SM_CurBlock(*pSM); while ( IsNonNULL(pCurBlock) ) { pNextBlock = SMBlk_NextBlock(pCurBlock); free(pCurBlock); pCurBlock = pNextBlock; } SM_CurBlock(*pSM) = SM_NextStruct(*pSM) = SM_LastStruct(*pSM) = NULL; SM_AllocList(*pSM) = SM_FreeList(*pSM) = NULL; }
void smFreeBlocks(Structure_Manager *pSM) { void *pCurBlock, *pNextBlock; pCurBlock = SM_CurBlock(*pSM); while ( IsNonNULL(pCurBlock) ) { pNextBlock = SMBlk_NextBlock(pCurBlock); mem_dealloc(pCurBlock,SM_NewBlockSize(*pSM),TABLE_SPACE); pCurBlock = pNextBlock; } SM_CurBlock(*pSM) = SM_NextStruct(*pSM) = SM_LastStruct(*pSM) = NULL; SM_AllocList(*pSM) = SM_FreeList(*pSM) = NULL; }
xsbBool smIsAllocatedStruct(Structure_Manager smRecord, void *pStruct) { void *freeStruct; /* Determine whether struct lies w/i unallocated section of 1st block ------------------------------------------------------------------ */ if ( (SM_NextStruct(smRecord) <= pStruct) && (pStruct <= SM_LastStruct(smRecord)) ) return FALSE; /* Determine whether struct is on the free list -------------------------------------------- */ for ( freeStruct = SM_FreeList(smRecord); IsNonNULL(freeStruct); freeStruct = SMFL_NextFreeStruct(freeStruct) ) if ( freeStruct == pStruct ) return FALSE; return TRUE; }
void smPrint(Structure_Manager smRecord, char *string) { void *pBlock; counter nBlocks; nBlocks = 0; for ( pBlock = SM_CurBlock(smRecord); IsNonNULL(pBlock); pBlock = SMBlk_NextBlock(pBlock) ) nBlocks++; fprintf(stddbg, " Structure Manager for %s (%s)\n" "\tCurBlock: %p\t\tTotal Blocks: %u\n" "\tNextStr: %p\t\tFree List: %p\n" "\tLastStr: %p\t\tAlloc List: %p\n" "\tStructs per block: %u\t\tStruct size: %u bytes\n", SM_StructName(smRecord), string, SM_CurBlock(smRecord), nBlocks, SM_NextStruct(smRecord), SM_FreeList(smRecord), SM_LastStruct(smRecord), SM_AllocList(smRecord), SM_StructsPerBlock(smRecord), SM_StructSize(smRecord)); }