108 p->nEntrySize = nEntrySize;
109 p->nEntriesAlloc = 0;
111 p->pEntriesFree = NULL;
113 if ( nEntrySize * (1 << 10) < (1<<16) )
114 p->nChunkSize = (1 << 10);
116 p->nChunkSize = (1<<16) / nEntrySize;
117 if ( p->nChunkSize < 8 )
120 p->nChunksAlloc = 64;
122 p->pChunks =
ABC_ALLOC(
char *, p->nChunksAlloc );
147 printf(
"Fixed memory manager: Entry = %5d. Chunk = %5d. Chunks used = %5d.\n",
148 p->nEntrySize, p->nChunkSize, p->nChunks );
149 printf(
" Entries used = %8d. Entries peak = %8d. Memory used = %8d. Memory alloc = %8d.\n",
150 p->nEntriesUsed, p->nEntriesMax, p->nEntrySize * p->nEntriesUsed, p->nMemoryAlloc );
152 for ( i = 0; i < p->nChunks; i++ )
175 if ( p->nEntriesUsed == p->nEntriesAlloc )
177 assert( p->pEntriesFree == NULL );
178 if ( p->nChunks == p->nChunksAlloc )
180 p->nChunksAlloc *= 2;
181 p->pChunks =
ABC_REALLOC(
char *, p->pChunks, p->nChunksAlloc );
183 p->pEntriesFree =
ABC_ALLOC(
char, p->nEntrySize * p->nChunkSize );
184 p->nMemoryAlloc += p->nEntrySize * p->nChunkSize;
186 pTemp = p->pEntriesFree;
187 for ( i = 1; i < p->nChunkSize; i++ )
189 *((
char **)pTemp) = pTemp + p->nEntrySize;
190 pTemp += p->nEntrySize;
193 *((
char **)pTemp) = NULL;
195 p->pChunks[ p->nChunks++ ] = p->pEntriesFree;
197 p->nEntriesAlloc += p->nChunkSize;
201 if ( p->nEntriesMax < p->nEntriesUsed )
202 p->nEntriesMax = p->nEntriesUsed;
204 pTemp = p->pEntriesFree;
205 p->pEntriesFree = *((
char **)pTemp);
225 *((
char **)pEntry) = p->pEntriesFree;
226 p->pEntriesFree = pEntry;
244 if ( p->nChunks == 0 )
249 for ( i = 1; i < p->nChunks; i++ )
253 pTemp = p->pChunks[0];
254 for ( i = 1; i < p->nChunkSize; i++ )
256 *((
char **)pTemp) = pTemp + p->nEntrySize;
257 pTemp += p->nEntrySize;
260 *((
char **)pTemp) = NULL;
262 p->pEntriesFree = p->pChunks[0];
264 p->nMemoryAlloc = p->nEntrySize * p->nChunkSize;
266 p->nEntriesAlloc = p->nChunkSize;
283 return p->nMemoryAlloc;
338 printf(
"Flexible memory manager: Chunk size = %d. Chunks used = %d.\n",
340 printf(
" Entries used = %d. Memory used = %d. Memory alloc = %d.\n",
343 for ( i = 0; i < p->
nChunks; i++ )
442 for ( i = 0; i < p->
nMems; i++ )
448 for ( k = 1; k <= 4; k++ )
451 for ( k = (4<<i)+1; k <= (8<<i); k++ )
477 for ( i = 0; i < p->
nChunks; i++ )
481 for ( i = 0; i < p->
nMems; i++ )
504 for ( i = 0; i < p->
nChunks; i++ )
508 for ( i = 0; i < p->
nMems; i++ )
577 int i, nMemTotal = 0;
578 for ( i = 0; i < p->
nMems; i++ )
579 nMemTotal += p->
pMems[i]->nMemoryAlloc;
char * Sat_MmFlexEntryFetch(Sat_MmFlex_t *p, int nBytes)
Sat_MmStep_t * Sat_MmStepStart(int nSteps)
Sat_MmFixed_t * Sat_MmFixedStart(int nEntrySize)
FUNCTION DEFINITIONS ///.
char * Sat_MmFixedEntryFetch(Sat_MmFixed_t *p)
#define ABC_REALLOC(type, obj, num)
void Sat_MmFixedStop(Sat_MmFixed_t *p, int fVerbose)
#define ABC_ALLOC(type, num)
Sat_MmFlex_t * Sat_MmFlexStart()
for(p=first;p->value< newval;p=p->next)
typedefABC_NAMESPACE_HEADER_START struct Sat_MmFixed_t_ Sat_MmFixed_t
INCLUDES ///.
void Sat_MmFixedRestart(Sat_MmFixed_t *p)
int Sat_MmFixedReadMemUsage(Sat_MmFixed_t *p)
#define ABC_NAMESPACE_IMPL_END
void Sat_MmStepRestart(Sat_MmStep_t *p)
void Sat_MmStepStop(Sat_MmStep_t *p, int fVerbose)
char * Sat_MmStepEntryFetch(Sat_MmStep_t *p, int nBytes)
#define ABC_NAMESPACE_IMPL_START
void Sat_MmStepEntryRecycle(Sat_MmStep_t *p, char *pEntry, int nBytes)
int Sat_MmFlexReadMemUsage(Sat_MmFlex_t *p)
void Sat_MmFlexStop(Sat_MmFlex_t *p, int fVerbose)
int Sat_MmStepReadMemUsage(Sat_MmStep_t *p)
void Sat_MmFixedEntryRecycle(Sat_MmFixed_t *p, char *pEntry)