107 p->nEntrySize = nEntrySize;
108 p->nEntriesAlloc = 0;
110 p->pEntriesFree = NULL;
112 if ( nEntrySize * (1 << 10) < (1<<16) )
113 p->nChunkSize = (1 << 10);
115 p->nChunkSize = (1<<16) / nEntrySize;
116 if ( p->nChunkSize < 8 )
119 p->nChunksAlloc = 64;
121 p->pChunks =
ABC_ALLOC(
char *, p->nChunksAlloc );
146 printf(
"Fixed memory manager: Entry = %5d. Chunk = %5d. Chunks used = %5d.\n",
147 p->nEntrySize, p->nChunkSize, p->nChunks );
148 printf(
" Entries used = %8d. Entries peak = %8d. Memory used = %8d. Memory alloc = %8d.\n",
149 p->nEntriesUsed, p->nEntriesMax, p->nEntrySize * p->nEntriesUsed, p->nMemoryAlloc );
151 for ( i = 0; i < p->nChunks; i++ )
174 if ( p->nEntriesUsed == p->nEntriesAlloc )
176 assert( p->pEntriesFree == NULL );
177 if ( p->nChunks == p->nChunksAlloc )
179 p->nChunksAlloc *= 2;
180 p->pChunks =
ABC_REALLOC(
char *, p->pChunks, p->nChunksAlloc );
182 p->pEntriesFree =
ABC_ALLOC(
char, p->nEntrySize * p->nChunkSize );
183 p->nMemoryAlloc += p->nEntrySize * p->nChunkSize;
185 pTemp = p->pEntriesFree;
186 for ( i = 1; i < p->nChunkSize; i++ )
188 *((
char **)pTemp) = pTemp + p->nEntrySize;
189 pTemp += p->nEntrySize;
192 *((
char **)pTemp) = NULL;
194 p->pChunks[ p->nChunks++ ] = p->pEntriesFree;
196 p->nEntriesAlloc += p->nChunkSize;
200 if ( p->nEntriesMax < p->nEntriesUsed )
201 p->nEntriesMax = p->nEntriesUsed;
203 pTemp = p->pEntriesFree;
204 p->pEntriesFree = *((
char **)pTemp);
224 *((
char **)pEntry) = p->pEntriesFree;
225 p->pEntriesFree = pEntry;
245 for ( i = 1; i < p->nChunks; i++ )
249 pTemp = p->pChunks[0];
250 for ( i = 1; i < p->nChunkSize; i++ )
252 *((
char **)pTemp) = pTemp + p->nEntrySize;
253 pTemp += p->nEntrySize;
256 *((
char **)pTemp) = NULL;
258 p->pEntriesFree = p->pChunks[0];
260 p->nMemoryAlloc = p->nEntrySize * p->nChunkSize;
262 p->nEntriesAlloc = p->nChunkSize;
279 return p->nMemoryAlloc;
295 return p->nEntriesMax;
350 printf(
"Flexible memory manager: Chunk size = %d. Chunks used = %d.\n",
352 printf(
" Entries used = %d. Memory used = %d. Memory alloc = %d.\n",
355 for ( i = 0; i < p->
nChunks; i++ )
423 for ( i = 1; i < p->
nChunks; i++ )
483 for ( i = 0; i < p->
nMems; i++ )
489 for ( k = 1; k <= 4; k++ )
492 for ( k = (4<<i)+1; k <= (8<<i); k++ )
513 for ( i = 0; i < p->
nMems; i++ )
595 int i, nMemTotal = 0;
596 for ( i = 0; i < p->
nMems; i++ )
597 nMemTotal += p->
pMems[i]->nMemoryAlloc;
void Mem_StepStop(Mem_Step_t *p, int fVerbose)
#define ABC_REALLOC(type, obj, num)
#define ABC_ALLOC(type, num)
void Mem_FixedStop(Mem_Fixed_t *p, int fVerbose)
for(p=first;p->value< newval;p=p->next)
int Mem_StepReadMemUsage(Mem_Step_t *p)
char * Mem_FlexEntryFetch(Mem_Flex_t *p, int nBytes)
void Mem_StepEntryRecycle(Mem_Step_t *p, char *pEntry, int nBytes)
Mem_Fixed_t * Mem_FixedStart(int nEntrySize)
FUNCTION DEFINITIONS ///.
Mem_Flex_t * Mem_FlexStart()
int Mem_FixedReadMaxEntriesUsed(Mem_Fixed_t *p)
#define ABC_NAMESPACE_IMPL_END
char * Mem_StepEntryFetch(Mem_Step_t *p, int nBytes)
void Mem_FixedEntryRecycle(Mem_Fixed_t *p, char *pEntry)
typedefABC_NAMESPACE_HEADER_START struct Mem_Fixed_t_ Mem_Fixed_t
DECLARATIONS ///.
Mem_Step_t * Mem_StepStart(int nSteps)
void Mem_FlexStop(Mem_Flex_t *p, int fVerbose)
#define ABC_NAMESPACE_IMPL_START
void Mem_FlexRestart(Mem_Flex_t *p)
void Mem_FixedRestart(Mem_Fixed_t *p)
int Mem_FlexReadMemUsage(Mem_Flex_t *p)
int Mem_FixedReadMemUsage(Mem_Fixed_t *p)
char * Mem_FixedEntryFetch(Mem_Fixed_t *p)