ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
mem.h File Reference
Include dependency graph for mem.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef typedefABC_NAMESPACE_HEADER_START struct Mem_Fixed_t_ Mem_Fixed_t
 DECLARATIONS ///.
 
typedef struct Mem_Flex_t_ Mem_Flex_t
 
typedef struct Mem_Step_t_ Mem_Step_t
 

Functions

Mem_Fixed_tMem_FixedStart (int nEntrySize)
 FUNCTION DEFINITIONS ///.
 
void Mem_FixedStop (Mem_Fixed_t *p, int fVerbose)
 
char * Mem_FixedEntryFetch (Mem_Fixed_t *p)
 
void Mem_FixedEntryRecycle (Mem_Fixed_t *p, char *pEntry)
 
void Mem_FixedRestart (Mem_Fixed_t *p)
 
int Mem_FixedReadMemUsage (Mem_Fixed_t *p)
 
int Mem_FixedReadMaxEntriesUsed (Mem_Fixed_t *p)
 
Mem_Flex_tMem_FlexStart ()
 
void Mem_FlexStop (Mem_Flex_t *p, int fVerbose)
 
void Mem_FlexStop2 (Mem_Flex_t *p)
 
char * Mem_FlexEntryFetch (Mem_Flex_t *p, int nBytes)
 
void Mem_FlexRestart (Mem_Flex_t *p)
 
int Mem_FlexReadMemUsage (Mem_Flex_t *p)
 
Mem_Step_tMem_StepStart (int nSteps)
 
void Mem_StepStop (Mem_Step_t *p, int fVerbose)
 
char * Mem_StepEntryFetch (Mem_Step_t *p, int nBytes)
 
void Mem_StepEntryRecycle (Mem_Step_t *p, char *pEntry, int nBytes)
 
int Mem_StepReadMemUsage (Mem_Step_t *p)
 

Typedef Documentation

◆ Mem_Fixed_t

typedef typedefABC_NAMESPACE_HEADER_START struct Mem_Fixed_t_ Mem_Fixed_t

DECLARATIONS ///.

CFile****************************************************************

FileName [mem.h]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Memory management.]

Synopsis [External declarations.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - June 20, 2005.]

Revision [

Id
mem.h,v 1.00 2005/06/20 00:00:00 alanmi Exp

]

Definition at line 33 of file mem.h.

◆ Mem_Flex_t

typedef struct Mem_Flex_t_ Mem_Flex_t

Definition at line 34 of file mem.h.

◆ Mem_Step_t

typedef struct Mem_Step_t_ Mem_Step_t

Definition at line 35 of file mem.h.

Function Documentation

◆ Mem_FixedEntryFetch()

char * Mem_FixedEntryFetch ( Mem_Fixed_t * p)
extern

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 184 of file mem.c.

185{
186 char * pTemp;
187 int i;
188
189 // check if there are still free entries
190 if ( p->nEntriesUsed == p->nEntriesAlloc )
191 { // need to allocate more entries
192 assert( p->pEntriesFree == NULL );
193 if ( p->nChunks == p->nChunksAlloc )
194 {
195 p->nChunksAlloc *= 2;
196 p->pChunks = ABC_REALLOC( char *, p->pChunks, p->nChunksAlloc );
197 }
198 p->pEntriesFree = ABC_ALLOC( char, p->nEntrySize * p->nChunkSize );
199 p->nMemoryAlloc += p->nEntrySize * p->nChunkSize;
200 // transform these entries into a linked list
201 pTemp = p->pEntriesFree;
202 for ( i = 1; i < p->nChunkSize; i++ )
203 {
204 *((char **)pTemp) = pTemp + p->nEntrySize;
205 pTemp += p->nEntrySize;
206 }
207 // set the last link
208 *((char **)pTemp) = NULL;
209 // add the chunk to the chunk storage
210 p->pChunks[ p->nChunks++ ] = p->pEntriesFree;
211 // add to the number of entries allocated
212 p->nEntriesAlloc += p->nChunkSize;
213 }
214 // incrememt the counter of used entries
215 p->nEntriesUsed++;
216 if ( p->nEntriesMax < p->nEntriesUsed )
217 p->nEntriesMax = p->nEntriesUsed;
218 // return the first entry in the free entry list
219 pTemp = p->pEntriesFree;
220 p->pEntriesFree = *((char **)pTemp);
221 return pTemp;
222}
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
#define ABC_REALLOC(type, obj, num)
Definition abc_global.h:268
Cube * p
Definition exorList.c:222
#define assert(ex)
Definition util_old.h:213
Here is the caller graph for this function:

◆ Mem_FixedEntryRecycle()

void Mem_FixedEntryRecycle ( Mem_Fixed_t * p,
char * pEntry )
extern

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 235 of file mem.c.

236{
237 // decrement the counter of used entries
238 p->nEntriesUsed--;
239 // add the entry to the linked list of free entries
240 *((char **)pEntry) = p->pEntriesFree;
241 p->pEntriesFree = pEntry;
242}
Here is the caller graph for this function:

◆ Mem_FixedReadMaxEntriesUsed()

int Mem_FixedReadMaxEntriesUsed ( Mem_Fixed_t * p)
extern

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 309 of file mem.c.

310{
311 return p->nEntriesMax;
312}

◆ Mem_FixedReadMemUsage()

int Mem_FixedReadMemUsage ( Mem_Fixed_t * p)
extern

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 293 of file mem.c.

294{
295 return p->nMemoryAlloc;
296}
Here is the caller graph for this function:

◆ Mem_FixedRestart()

void Mem_FixedRestart ( Mem_Fixed_t * p)
extern

Function*************************************************************

Synopsis []

Description [Relocates all the memory except the first chunk.]

SideEffects []

SeeAlso []

Definition at line 255 of file mem.c.

256{
257 int i;
258 char * pTemp;
259
260 // deallocate all chunks except the first one
261 for ( i = 1; i < p->nChunks; i++ )
262 ABC_FREE( p->pChunks[i] );
263 p->nChunks = 1;
264 // transform these entries into a linked list
265 pTemp = p->pChunks[0];
266 for ( i = 1; i < p->nChunkSize; i++ )
267 {
268 *((char **)pTemp) = pTemp + p->nEntrySize;
269 pTemp += p->nEntrySize;
270 }
271 // set the last link
272 *((char **)pTemp) = NULL;
273 // set the free entry list
274 p->pEntriesFree = p->pChunks[0];
275 // set the correct statistics
276 p->nMemoryAlloc = p->nEntrySize * p->nChunkSize;
277 p->nMemoryUsed = 0;
278 p->nEntriesAlloc = p->nChunkSize;
279 p->nEntriesUsed = 0;
280}
#define ABC_FREE(obj)
Definition abc_global.h:267
Here is the caller graph for this function:

◆ Mem_FixedStart()

Mem_Fixed_t * Mem_FixedStart ( int nEntrySize)
extern

FUNCTION DEFINITIONS ///.

Function*************************************************************

Synopsis [Allocates memory pieces of fixed size.]

Description [The size of the chunk is computed as the minimum of 1024 entries and 64K. Can only work with entry size at least 4 byte long.]

SideEffects []

SeeAlso []

Definition at line 100 of file mem.c.

101{
102 Mem_Fixed_t * p;
103
104 p = ABC_ALLOC( Mem_Fixed_t, 1 );
105 memset( p, 0, sizeof(Mem_Fixed_t) );
106
107 p->nEntrySize = nEntrySize;
108 p->nEntriesAlloc = 0;
109 p->nEntriesUsed = 0;
110 p->pEntriesFree = NULL;
111
112 if ( nEntrySize * (1 << 10) < (1<<16) )
113 p->nChunkSize = (1 << 10);
114 else
115 p->nChunkSize = (1<<16) / nEntrySize;
116 if ( p->nChunkSize < 8 )
117 p->nChunkSize = 8;
118
119 p->nChunksAlloc = 64;
120 p->nChunks = 0;
121 p->pChunks = ABC_ALLOC( char *, p->nChunksAlloc );
122
123 p->nMemoryUsed = 0;
124 p->nMemoryAlloc = 0;
125 return p;
126}
typedefABC_NAMESPACE_HEADER_START struct Mem_Fixed_t_ Mem_Fixed_t
DECLARATIONS ///.
Definition mem.h:33
char * memset()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Mem_FixedStop()

void Mem_FixedStop ( Mem_Fixed_t * p,
int fVerbose )
extern

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 139 of file mem.c.

140{
141 int i;
142 if ( p == NULL )
143 return;
144 if ( fVerbose )
145 {
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 );
150 }
151 for ( i = 0; i < p->nChunks; i++ )
152 ABC_FREE( p->pChunks[i] );
153 ABC_FREE( p->pChunks );
154 ABC_FREE( p );
155}
Here is the caller graph for this function:

◆ Mem_FlexEntryFetch()

char * Mem_FlexEntryFetch ( Mem_Flex_t * p,
int nBytes )
extern

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 388 of file mem.c.

389{
390 char * pTemp;
391 // check if there are still free entries
392 if ( p->pCurrent == NULL || p->pCurrent + nBytes > p->pEnd )
393 { // need to allocate more entries
394 if ( p->nChunks == p->nChunksAlloc )
395 {
396 p->nChunksAlloc *= 2;
397 p->pChunks = ABC_REALLOC( char *, p->pChunks, p->nChunksAlloc );
398 }
399 if ( nBytes > p->nChunkSize )
400 {
401 // resize the chunk size if more memory is requested than it can give
402 // (ideally, this should never happen)
403 p->nChunkSize = 2 * nBytes;
404 }
405 p->pCurrent = ABC_ALLOC( char, p->nChunkSize );
406 p->pEnd = p->pCurrent + p->nChunkSize;
407 p->nMemoryAlloc += p->nChunkSize;
408 // add the chunk to the chunk storage
409 p->pChunks[ p->nChunks++ ] = p->pCurrent;
410 }
411 assert( p->pCurrent + nBytes <= p->pEnd );
412 // increment the counter of used entries
413 p->nEntriesUsed++;
414 // keep track of the memory used
415 p->nMemoryUsed += nBytes;
416 // return the next entry
417 pTemp = p->pCurrent;
418 p->pCurrent += nBytes;
419 return pTemp;
420}
Here is the caller graph for this function:

◆ Mem_FlexReadMemUsage()

int Mem_FlexReadMemUsage ( Mem_Flex_t * p)
extern

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 461 of file mem.c.

462{
463 return p->nMemoryUsed;
464}
Here is the caller graph for this function:

◆ Mem_FlexRestart()

void Mem_FlexRestart ( Mem_Flex_t * p)
extern

Function*************************************************************

Synopsis []

Description [Relocates all the memory except the first chunk.]

SideEffects []

SeeAlso []

Definition at line 433 of file mem.c.

434{
435 int i;
436 if ( p->nChunks == 0 )
437 return;
438 // deallocate all chunks except the first one
439 for ( i = 1; i < p->nChunks; i++ )
440 ABC_FREE( p->pChunks[i] );
441 p->nChunks = 1;
442 p->nMemoryAlloc = p->nChunkSize;
443 // transform these entries into a linked list
444 p->pCurrent = p->pChunks[0];
445 p->pEnd = p->pCurrent + p->nChunkSize;
446 p->nEntriesUsed = 0;
447 p->nMemoryUsed = 0;
448}

◆ Mem_FlexStart()

Mem_Flex_t * Mem_FlexStart ( )
extern

Function*************************************************************

Synopsis [Allocates entries of flexible size.]

Description [Can only work with entry size at least 4 byte long.]

SideEffects []

SeeAlso []

Definition at line 327 of file mem.c.

328{
329 Mem_Flex_t * p;
330
331 p = ABC_ALLOC( Mem_Flex_t, 1 );
332 memset( p, 0, sizeof(Mem_Flex_t) );
333
334 p->nEntriesUsed = 0;
335 p->pCurrent = NULL;
336 p->pEnd = NULL;
337
338 p->nChunkSize = (1 << 12);
339 p->nChunksAlloc = 64;
340 p->nChunks = 0;
341 p->pChunks = ABC_ALLOC( char *, p->nChunksAlloc );
342
343 p->nMemoryUsed = 0;
344 p->nMemoryAlloc = 0;
345 return p;
346}
struct Mem_Flex_t_ Mem_Flex_t
Definition mem.h:34
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Mem_FlexStop()

void Mem_FlexStop ( Mem_Flex_t * p,
int fVerbose )
extern

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 359 of file mem.c.

360{
361 int i;
362 if ( p == NULL )
363 return;
364 if ( fVerbose )
365 {
366 printf( "Flexible memory manager: Chunk size = %d. Chunks used = %d.\n",
367 p->nChunkSize, p->nChunks );
368 printf( " Entries used = %d. Memory used = %d. Memory alloc = %d.\n",
369 p->nEntriesUsed, p->nMemoryUsed, p->nMemoryAlloc );
370 }
371 for ( i = 0; i < p->nChunks; i++ )
372 ABC_FREE( p->pChunks[i] );
373 ABC_FREE( p->pChunks );
374 ABC_FREE( p );
375}
Here is the caller graph for this function:

◆ Mem_FlexStop2()

void Mem_FlexStop2 ( Mem_Flex_t * p)
extern

Function*************************************************************

Synopsis [Wrapper for Mem_FlexStop for use in Vec_AttAlloc]

Description []

SideEffects []

SeeAlso []

Definition at line 168 of file mem.c.

169{
170 Mem_FlexStop( p, 0 );
171}
void Mem_FlexStop(Mem_Flex_t *p, int fVerbose)
Definition mem.c:359
Here is the call graph for this function:

◆ Mem_StepEntryFetch()

char * Mem_StepEntryFetch ( Mem_Step_t * p,
int nBytes )
extern

Function*************************************************************

Synopsis [Creates the entry.]

Description []

SideEffects []

SeeAlso []

Definition at line 553 of file mem.c.

554{
555 if ( nBytes == 0 )
556 return NULL;
557 if ( nBytes > p->nMapSize )
558 {
559// printf( "Allocating %d bytes.\n", nBytes );
560// return ABC_ALLOC( char, nBytes );
561 if ( p->nLargeChunks == p->nLargeChunksAlloc )
562 {
563 if ( p->nLargeChunksAlloc == 0 )
564 p->nLargeChunksAlloc = 32;
565 p->nLargeChunksAlloc *= 2;
566 p->pLargeChunks = (void **)ABC_REALLOC( char *, p->pLargeChunks, p->nLargeChunksAlloc );
567 }
568 p->pLargeChunks[ p->nLargeChunks++ ] = ABC_ALLOC( char, nBytes );
569 return (char *)p->pLargeChunks[ p->nLargeChunks - 1 ];
570 }
571 return Mem_FixedEntryFetch( p->pMap[nBytes] );
572}
char * Mem_FixedEntryFetch(Mem_Fixed_t *p)
Definition mem.c:184
Here is the call graph for this function:

◆ Mem_StepEntryRecycle()

void Mem_StepEntryRecycle ( Mem_Step_t * p,
char * pEntry,
int nBytes )
extern

Function*************************************************************

Synopsis [Recycles the entry.]

Description []

SideEffects []

SeeAlso []

Definition at line 586 of file mem.c.

587{
588 if ( nBytes == 0 )
589 return;
590 if ( nBytes > p->nMapSize )
591 {
592// ABC_FREE( pEntry );
593 return;
594 }
595 Mem_FixedEntryRecycle( p->pMap[nBytes], pEntry );
596}
void Mem_FixedEntryRecycle(Mem_Fixed_t *p, char *pEntry)
Definition mem.c:235
Here is the call graph for this function:

◆ Mem_StepReadMemUsage()

int Mem_StepReadMemUsage ( Mem_Step_t * p)
extern

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 609 of file mem.c.

610{
611 int i, nMemTotal = 0;
612 for ( i = 0; i < p->nMems; i++ )
613 nMemTotal += p->pMems[i]->nMemoryAlloc;
614 return nMemTotal;
615}
Here is the caller graph for this function:

◆ Mem_StepStart()

Mem_Step_t * Mem_StepStart ( int nSteps)
extern

Function*************************************************************

Synopsis [Starts the hierarchical memory manager.]

Description [This manager can allocate entries of any size. Iternally they are mapped into the entries with the number of bytes equal to the power of 2. The smallest entry size is 8 bytes. The next one is 16 bytes etc. So, if the user requests 6 bytes, he gets 8 byte entry. If we asks for 25 bytes, he gets 32 byte entry etc. The input parameters "nSteps" says how many fixed memory managers 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 ABC_FREE()ed.]

SideEffects []

SeeAlso []

Definition at line 490 of file mem.c.

491{
492 Mem_Step_t * p;
493 int i, k;
494 p = ABC_ALLOC( Mem_Step_t, 1 );
495 memset( p, 0, sizeof(Mem_Step_t) );
496 p->nMems = nSteps;
497 // start the fixed memory managers
498 p->pMems = ABC_ALLOC( Mem_Fixed_t *, p->nMems );
499 for ( i = 0; i < p->nMems; i++ )
500 p->pMems[i] = Mem_FixedStart( (8<<i) );
501 // set up the mapping of the required memory size into the corresponding manager
502 p->nMapSize = (4<<p->nMems);
503 p->pMap = ABC_ALLOC( Mem_Fixed_t *, p->nMapSize+1 );
504 p->pMap[0] = NULL;
505 for ( k = 1; k <= 4; k++ )
506 p->pMap[k] = p->pMems[0];
507 for ( i = 0; i < p->nMems; i++ )
508 for ( k = (4<<i)+1; k <= (8<<i); k++ )
509 p->pMap[k] = p->pMems[i];
510//for ( i = 1; i < 100; i ++ )
511//printf( "%10d: size = %10d\n", i, p->pMap[i]->nEntrySize );
512 return p;
513}
Mem_Fixed_t * Mem_FixedStart(int nEntrySize)
FUNCTION DEFINITIONS ///.
Definition mem.c:100
struct Mem_Step_t_ Mem_Step_t
Definition mem.h:35
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Mem_StepStop()

void Mem_StepStop ( Mem_Step_t * p,
int fVerbose )
extern

Function*************************************************************

Synopsis [Stops the memory manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 526 of file mem.c.

527{
528 int i;
529 for ( i = 0; i < p->nMems; i++ )
530 Mem_FixedStop( p->pMems[i], fVerbose );
531 if ( p->pLargeChunks )
532 {
533 for ( i = 0; i < p->nLargeChunks; i++ )
534 ABC_FREE( p->pLargeChunks[i] );
535 ABC_FREE( p->pLargeChunks );
536 }
537 ABC_FREE( p->pMems );
538 ABC_FREE( p->pMap );
539 ABC_FREE( p );
540}
void Mem_FixedStop(Mem_Fixed_t *p, int fVerbose)
Definition mem.c:139
Here is the call graph for this function:
Here is the caller graph for this function: