diff options
author | Alan Mishchenko <alanmi@berkeley.edu> | 2009-02-15 08:01:00 -0800 |
---|---|---|
committer | Alan Mishchenko <alanmi@berkeley.edu> | 2009-02-15 08:01:00 -0800 |
commit | 0871bffae307e0553e0c5186336189e8b55cf6a6 (patch) | |
tree | 4571d1563fe33a53a57fea1c35fb668b9d33265f /src/misc/extra/extraUtilMemory.c | |
parent | f936cc0680c98ffe51b3a1716c996072d5dbf76c (diff) | |
download | abc-0871bffae307e0553e0c5186336189e8b55cf6a6.tar.gz abc-0871bffae307e0553e0c5186336189e8b55cf6a6.tar.bz2 abc-0871bffae307e0553e0c5186336189e8b55cf6a6.zip |
Version abc90215
Diffstat (limited to 'src/misc/extra/extraUtilMemory.c')
-rw-r--r-- | src/misc/extra/extraUtilMemory.c | 72 |
1 files changed, 36 insertions, 36 deletions
diff --git a/src/misc/extra/extraUtilMemory.c b/src/misc/extra/extraUtilMemory.c index e672afbb..626d58b5 100644 --- a/src/misc/extra/extraUtilMemory.c +++ b/src/misc/extra/extraUtilMemory.c @@ -35,7 +35,7 @@ struct Extra_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 @@ -52,8 +52,8 @@ struct Extra_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 @@ -120,7 +120,7 @@ Extra_MmFixed_t * Extra_MmFixedStart( int nEntrySize ) { Extra_MmFixed_t * p; - p = ALLOC( Extra_MmFixed_t, 1 ); + p = ABC_ALLOC( Extra_MmFixed_t, 1 ); memset( p, 0, sizeof(Extra_MmFixed_t) ); p->nEntrySize = nEntrySize; @@ -137,7 +137,7 @@ Extra_MmFixed_t * Extra_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; @@ -180,9 +180,9 @@ void Extra_MmFixedStop( Extra_MmFixed_t * p ) if ( p == NULL ) return; 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************************************************************* @@ -201,16 +201,16 @@ char * Extra_MmFixedEntryFetch( Extra_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; @@ -230,7 +230,7 @@ char * Extra_MmFixedEntryFetch( Extra_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; @@ -251,7 +251,7 @@ void Extra_MmFixedEntryRecycle( Extra_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; } @@ -274,7 +274,7 @@ void Extra_MmFixedRestart( Extra_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]; @@ -285,7 +285,7 @@ void Extra_MmFixedRestart( Extra_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; @@ -342,7 +342,7 @@ Extra_MmFlex_t * Extra_MmFlexStart() { Extra_MmFlex_t * p; //printf( "allocing flex\n" ); - p = ALLOC( Extra_MmFlex_t, 1 ); + p = ABC_ALLOC( Extra_MmFlex_t, 1 ); memset( p, 0, sizeof(Extra_MmFlex_t) ); p->nEntriesUsed = 0; @@ -352,7 +352,7 @@ Extra_MmFlex_t * Extra_MmFlexStart() p->nChunkSize = (1 << 12); 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; @@ -396,9 +396,9 @@ void Extra_MmFlexStop( Extra_MmFlex_t * p ) return; //printf( "deleting flex\n" ); 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************************************************************* @@ -415,13 +415,13 @@ void Extra_MmFlexStop( Extra_MmFlex_t * p ) char * Extra_MmFlexEntryFetch( Extra_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 ) { @@ -429,7 +429,7 @@ char * Extra_MmFlexEntryFetch( Extra_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 @@ -479,7 +479,7 @@ int Extra_MmFlexReadMemUsage( Extra_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 [] @@ -490,16 +490,16 @@ Extra_MmStep_t * Extra_MmStepStart( int nSteps ) { Extra_MmStep_t * p; int i, k; - p = ALLOC( Extra_MmStep_t, 1 ); + p = ABC_ALLOC( Extra_MmStep_t, 1 ); memset( p, 0, sizeof(Extra_MmStep_t) ); p->nMems = nSteps; // start the fixed memory managers - p->pMems = ALLOC( Extra_MmFixed_t *, p->nMems ); + p->pMems = ABC_ALLOC( Extra_MmFixed_t *, p->nMems ); for ( i = 0; i < p->nMems; i++ ) p->pMems[i] = Extra_MmFixedStart( (8<<i) ); // set up the mapping of the required memory size into the corresponding manager p->nMapSize = (4<<p->nMems); - p->pMap = ALLOC( Extra_MmFixed_t *, p->nMapSize+1 ); + p->pMap = ABC_ALLOC( Extra_MmFixed_t *, p->nMapSize+1 ); p->pMap[0] = NULL; for ( k = 1; k <= 4; k++ ) p->pMap[k] = p->pMems[0]; @@ -530,12 +530,12 @@ void Extra_MmStepStop( Extra_MmStep_t * p ) if ( p->pLargeChunks ) { for ( i = 0; i < p->nLargeChunks; i++ ) - free( p->pLargeChunks[i] ); - free( p->pLargeChunks ); + ABC_FREE( p->pLargeChunks[i] ); + ABC_FREE( p->pLargeChunks ); } - free( p->pMems ); - free( p->pMap ); - free( p ); + ABC_FREE( p->pMems ); + ABC_FREE( p->pMap ); + ABC_FREE( p ); } /**Function************************************************************* @@ -556,15 +556,15 @@ char * Extra_MmStepEntryFetch( Extra_MmStep_t * p, int nBytes ) if ( nBytes > p->nMapSize ) { // printf( "Allocating %d bytes.\n", nBytes ); -// return ALLOC( char, nBytes ); +// return ABC_ALLOC( char, nBytes ); if ( p->nLargeChunks == p->nLargeChunksAlloc ) { if ( p->nLargeChunksAlloc == 0 ) p->nLargeChunksAlloc = 32; p->nLargeChunksAlloc *= 2; - p->pLargeChunks = REALLOC( void *, p->pLargeChunks, p->nLargeChunksAlloc ); + p->pLargeChunks = ABC_REALLOC( void *, p->pLargeChunks, p->nLargeChunksAlloc ); } - p->pLargeChunks[ p->nLargeChunks++ ] = ALLOC( char, nBytes ); + p->pLargeChunks[ p->nLargeChunks++ ] = ABC_ALLOC( char, nBytes ); return p->pLargeChunks[ p->nLargeChunks - 1 ]; } return Extra_MmFixedEntryFetch( p->pMap[nBytes] ); @@ -588,7 +588,7 @@ void Extra_MmStepEntryRecycle( Extra_MmStep_t * p, char * pEntry, int nBytes ) return; if ( nBytes > p->nMapSize ) { -// free( pEntry ); +// ABC_FREE( pEntry ); return; } Extra_MmFixedEntryRecycle( p->pMap[nBytes], pEntry ); |