From 0871bffae307e0553e0c5186336189e8b55cf6a6 Mon Sep 17 00:00:00 2001 From: Alan Mishchenko Date: Sun, 15 Feb 2009 08:01:00 -0800 Subject: Version abc90215 --- src/sat/bsat/satMem.c | 79 +++++++++++++++++++++++++++------------------------ 1 file changed, 42 insertions(+), 37 deletions(-) (limited to 'src/sat/bsat/satMem.c') diff --git a/src/sat/bsat/satMem.c b/src/sat/bsat/satMem.c index 1dacb854..f789f927 100644 --- a/src/sat/bsat/satMem.c +++ b/src/sat/bsat/satMem.c @@ -16,8 +16,13 @@ ***********************************************************************/ +#include +#include +#include +#include + +#include "abc_global.h" #include "satMem.h" -#include "vec.h" //////////////////////////////////////////////////////////////////////// /// DECLARATIONS /// @@ -30,7 +35,7 @@ struct Sat_MmFixed_t_ int nEntriesAlloc; // the total number of entries allocated int nEntriesUsed; // the number of entries in use int nEntriesMax; // the max number of entries in use - char * pEntriesFree; // the linked list of free entries + char * pEntriesFree; // the linked list of ABC_FREE entries // this is where the memory is stored int nChunkSize; // the size of one chunk @@ -47,8 +52,8 @@ struct Sat_MmFlex_t_ { // information about individual entries int nEntriesUsed; // the number of entries allocated - char * pCurrent; // the current pointer to free memory - char * pEnd; // the first entry outside the free memory + char * pCurrent; // the current pointer to ABC_FREE memory + char * pEnd; // the first entry outside the ABC_FREE memory // this is where the memory is stored int nChunkSize; // the size of one chunk @@ -93,7 +98,7 @@ Sat_MmFixed_t * Sat_MmFixedStart( int nEntrySize ) { Sat_MmFixed_t * p; - p = ALLOC( Sat_MmFixed_t, 1 ); + p = ABC_ALLOC( Sat_MmFixed_t, 1 ); memset( p, 0, sizeof(Sat_MmFixed_t) ); p->nEntrySize = nEntrySize; @@ -110,7 +115,7 @@ Sat_MmFixed_t * Sat_MmFixedStart( int nEntrySize ) p->nChunksAlloc = 64; p->nChunks = 0; - p->pChunks = ALLOC( char *, p->nChunksAlloc ); + p->pChunks = ABC_ALLOC( char *, p->nChunksAlloc ); p->nMemoryUsed = 0; p->nMemoryAlloc = 0; @@ -141,9 +146,9 @@ void Sat_MmFixedStop( Sat_MmFixed_t * p, int fVerbose ) p->nEntriesUsed, p->nEntriesMax, p->nEntrySize * p->nEntriesUsed, p->nMemoryAlloc ); } for ( i = 0; i < p->nChunks; i++ ) - free( p->pChunks[i] ); - free( p->pChunks ); - free( p ); + ABC_FREE( p->pChunks[i] ); + ABC_FREE( p->pChunks ); + ABC_FREE( p ); } /**Function************************************************************* @@ -162,16 +167,16 @@ char * Sat_MmFixedEntryFetch( Sat_MmFixed_t * p ) char * pTemp; int i; - // check if there are still free entries + // check if there are still ABC_FREE entries if ( p->nEntriesUsed == p->nEntriesAlloc ) { // need to allocate more entries assert( p->pEntriesFree == NULL ); if ( p->nChunks == p->nChunksAlloc ) { p->nChunksAlloc *= 2; - p->pChunks = REALLOC( char *, p->pChunks, p->nChunksAlloc ); + p->pChunks = ABC_REALLOC( char *, p->pChunks, p->nChunksAlloc ); } - p->pEntriesFree = ALLOC( char, p->nEntrySize * p->nChunkSize ); + p->pEntriesFree = ABC_ALLOC( char, p->nEntrySize * p->nChunkSize ); p->nMemoryAlloc += p->nEntrySize * p->nChunkSize; // transform these entries into a linked list pTemp = p->pEntriesFree; @@ -191,7 +196,7 @@ char * Sat_MmFixedEntryFetch( Sat_MmFixed_t * p ) p->nEntriesUsed++; if ( p->nEntriesMax < p->nEntriesUsed ) p->nEntriesMax = p->nEntriesUsed; - // return the first entry in the free entry list + // return the first entry in the ABC_FREE entry list pTemp = p->pEntriesFree; p->pEntriesFree = *((char **)pTemp); return pTemp; @@ -212,7 +217,7 @@ void Sat_MmFixedEntryRecycle( Sat_MmFixed_t * p, char * pEntry ) { // decrement the counter of used entries p->nEntriesUsed--; - // add the entry to the linked list of free entries + // add the entry to the linked list of ABC_FREE entries *((char **)pEntry) = p->pEntriesFree; p->pEntriesFree = pEntry; } @@ -235,7 +240,7 @@ void Sat_MmFixedRestart( Sat_MmFixed_t * p ) // deallocate all chunks except the first one for ( i = 1; i < p->nChunks; i++ ) - free( p->pChunks[i] ); + ABC_FREE( p->pChunks[i] ); p->nChunks = 1; // transform these entries into a linked list pTemp = p->pChunks[0]; @@ -246,7 +251,7 @@ void Sat_MmFixedRestart( Sat_MmFixed_t * p ) } // set the last link *((char **)pTemp) = NULL; - // set the free entry list + // set the ABC_FREE entry list p->pEntriesFree = p->pChunks[0]; // set the correct statistics p->nMemoryAlloc = p->nEntrySize * p->nChunkSize; @@ -288,7 +293,7 @@ Sat_MmFlex_t * Sat_MmFlexStart() { Sat_MmFlex_t * p; - p = ALLOC( Sat_MmFlex_t, 1 ); + p = ABC_ALLOC( Sat_MmFlex_t, 1 ); memset( p, 0, sizeof(Sat_MmFlex_t) ); p->nEntriesUsed = 0; @@ -298,7 +303,7 @@ Sat_MmFlex_t * Sat_MmFlexStart() p->nChunkSize = (1 << 16); p->nChunksAlloc = 64; p->nChunks = 0; - p->pChunks = ALLOC( char *, p->nChunksAlloc ); + p->pChunks = ABC_ALLOC( char *, p->nChunksAlloc ); p->nMemoryUsed = 0; p->nMemoryAlloc = 0; @@ -329,9 +334,9 @@ void Sat_MmFlexStop( Sat_MmFlex_t * p, int fVerbose ) p->nEntriesUsed, p->nMemoryUsed, p->nMemoryAlloc ); } for ( i = 0; i < p->nChunks; i++ ) - free( p->pChunks[i] ); - free( p->pChunks ); - free( p ); + ABC_FREE( p->pChunks[i] ); + ABC_FREE( p->pChunks ); + ABC_FREE( p ); } /**Function************************************************************* @@ -348,13 +353,13 @@ void Sat_MmFlexStop( Sat_MmFlex_t * p, int fVerbose ) char * Sat_MmFlexEntryFetch( Sat_MmFlex_t * p, int nBytes ) { char * pTemp; - // check if there are still free entries + // check if there are still ABC_FREE entries if ( p->pCurrent == NULL || p->pCurrent + nBytes > p->pEnd ) { // need to allocate more entries if ( p->nChunks == p->nChunksAlloc ) { p->nChunksAlloc *= 2; - p->pChunks = REALLOC( char *, p->pChunks, p->nChunksAlloc ); + p->pChunks = ABC_REALLOC( char *, p->pChunks, p->nChunksAlloc ); } if ( nBytes > p->nChunkSize ) { @@ -362,7 +367,7 @@ char * Sat_MmFlexEntryFetch( Sat_MmFlex_t * p, int nBytes ) // (ideally, this should never happen) p->nChunkSize = 2 * nBytes; } - p->pCurrent = ALLOC( char, p->nChunkSize ); + p->pCurrent = ABC_ALLOC( char, p->nChunkSize ); p->pEnd = p->pCurrent + p->nChunkSize; p->nMemoryAlloc += p->nChunkSize; // add the chunk to the chunk storage @@ -412,7 +417,7 @@ int Sat_MmFlexReadMemUsage( Sat_MmFlex_t * p ) are employed internally. Calling this procedure with nSteps equal to 10 results in 10 hierarchically arranged internal memory managers, which can allocate up to 4096 (1Kb) entries. Requests for larger - entries are handed over to malloc() and then free()ed.] + entries are handed over to malloc() and then ABC_FREE()ed.] SideEffects [] @@ -423,15 +428,15 @@ Sat_MmStep_t * Sat_MmStepStart( int nSteps ) { Sat_MmStep_t * p; int i, k; - p = ALLOC( Sat_MmStep_t, 1 ); + p = ABC_ALLOC( Sat_MmStep_t, 1 ); p->nMems = nSteps; // start the fixed memory managers - p->pMems = ALLOC( Sat_MmFixed_t *, p->nMems ); + p->pMems = ABC_ALLOC( Sat_MmFixed_t *, p->nMems ); for ( i = 0; i < p->nMems; i++ ) p->pMems[i] = Sat_MmFixedStart( (8<nMapSize = (4<nMems); - p->pMap = ALLOC( Sat_MmFixed_t *, p->nMapSize+1 ); + p->pMap = ABC_ALLOC( Sat_MmFixed_t *, p->nMapSize+1 ); p->pMap[0] = NULL; for ( k = 1; k <= 4; k++ ) p->pMap[k] = p->pMems[0]; @@ -442,7 +447,7 @@ Sat_MmStep_t * Sat_MmStepStart( int nSteps ) //printf( "%10d: size = %10d\n", i, p->pMap[i]->nEntrySize ); p->nChunksAlloc = 64; p->nChunks = 0; - p->pChunks = ALLOC( char *, p->nChunksAlloc ); + p->pChunks = ABC_ALLOC( char *, p->nChunksAlloc ); return p; } @@ -463,14 +468,14 @@ void Sat_MmStepStop( Sat_MmStep_t * p, int fVerbose ) if ( p->nChunksAlloc ) { for ( i = 0; i < p->nChunks; i++ ) - free( p->pChunks[i] ); - free( p->pChunks ); + ABC_FREE( p->pChunks[i] ); + ABC_FREE( p->pChunks ); } for ( i = 0; i < p->nMems; i++ ) Sat_MmFixedStop( p->pMems[i], fVerbose ); - free( p->pMems ); - free( p->pMap ); - free( p ); + ABC_FREE( p->pMems ); + ABC_FREE( p->pMap ); + ABC_FREE( p ); } /**Function************************************************************* @@ -493,9 +498,9 @@ char * Sat_MmStepEntryFetch( Sat_MmStep_t * p, int nBytes ) if ( p->nChunks == p->nChunksAlloc ) { p->nChunksAlloc *= 2; - p->pChunks = REALLOC( char *, p->pChunks, p->nChunksAlloc ); + p->pChunks = ABC_REALLOC( char *, p->pChunks, p->nChunksAlloc ); } - p->pChunks[ p->nChunks++ ] = ALLOC( char, nBytes ); + p->pChunks[ p->nChunks++ ] = ABC_ALLOC( char, nBytes ); return p->pChunks[p->nChunks-1]; } return Sat_MmFixedEntryFetch( p->pMap[nBytes] ); @@ -519,7 +524,7 @@ void Sat_MmStepEntryRecycle( Sat_MmStep_t * p, char * pEntry, int nBytes ) return; if ( nBytes > p->nMapSize ) { -// free( pEntry ); +// ABC_FREE( pEntry ); return; } Sat_MmFixedEntryRecycle( p->pMap[nBytes], pEntry ); -- cgit v1.2.3