abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
utilMem.c File Reference
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include "abc_global.h"

Go to the source code of this file.

Data Structures

struct  Vec_Mem_t_
 

Macros

#define ABC_MEM_ALLOC(type, num)   ((type *) malloc(sizeof(type) * (num)))
 
#define ABC_MEM_CALLOC(type, num)   ((type *) calloc((num), sizeof(type)))
 
#define ABC_MEM_FALLOC(type, num)   ((type *) memset(malloc(sizeof(type) * (num)), 0xff, sizeof(type) * (num)))
 
#define ABC_MEM_FREE(obj)   ((obj) ? (free((char *) (obj)), (obj) = 0) : 0)
 
#define ABC_MEM_REALLOC(type, obj, num)
 

Typedefs

typedef
typedefABC_NAMESPACE_IMPL_START
struct Vec_Mem_t_ 
Vec_Mem_t
 DECLARATIONS ///. More...
 

Functions

static Vec_Mem_tVec_MemAlloc (int nCap)
 FUNCTION DEFINITIONS ///. More...
 
static void Vec_MemFree (Vec_Mem_t *p)
 
static void Vec_MemGrow (Vec_Mem_t *p, int nCapMin)
 
static void Vec_MemPush (Vec_Mem_t *p, void *Entry)
 
static void Vec_MemSort (Vec_Mem_t *p, int(*Vec_MemSortCompare)())
 
void * Util_MemRecAlloc (void *pMem)
 BASIC TYPES ///. More...
 
void * Util_MemRecFree (void *pMem)
 
int Util_ComparePointers (void **pp1, void **pp2)
 
static Vec_Mem_tVec_MemTwoMerge (Vec_Mem_t *vArr1, Vec_Mem_t *vArr2)
 
void Util_MemRecRecycle ()
 
void Util_MemRecStart ()
 
void Util_MemRecQuit ()
 
int Util_MemRecIsSet ()
 

Variables

void * s_vAllocs = NULL
 INCLUDES ///. More...
 
void * s_vFrees = NULL
 
int s_fInterrupt = 0
 

Macro Definition Documentation

#define ABC_MEM_ALLOC (   type,
  num 
)    ((type *) malloc(sizeof(type) * (num)))

Definition at line 47 of file utilMem.c.

#define ABC_MEM_CALLOC (   type,
  num 
)    ((type *) calloc((num), sizeof(type)))

Definition at line 48 of file utilMem.c.

#define ABC_MEM_FALLOC (   type,
  num 
)    ((type *) memset(malloc(sizeof(type) * (num)), 0xff, sizeof(type) * (num)))

Definition at line 49 of file utilMem.c.

#define ABC_MEM_FREE (   obj)    ((obj) ? (free((char *) (obj)), (obj) = 0) : 0)

Definition at line 50 of file utilMem.c.

#define ABC_MEM_REALLOC (   type,
  obj,
  num 
)
Value:
((obj) ? ((type *) realloc((char *)(obj), sizeof(type) * (num))) : \
((type *) malloc(sizeof(type) * (num))))
char * malloc()
char * realloc()

Definition at line 51 of file utilMem.c.

Typedef Documentation

typedef typedefABC_NAMESPACE_IMPL_START struct Vec_Mem_t_ Vec_Mem_t

DECLARATIONS ///.

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

FileName [utilMem.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Memory recycling utilities.]

Synopsis [Memory recycling utilities.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

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

Revision [

Id:
utilMem.c,v 1.00 2005/06/20 00:00:00 alanmi Exp

]

Definition at line 35 of file utilMem.c.

Function Documentation

int Util_ComparePointers ( void **  pp1,
void **  pp2 
)

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

Synopsis [Procedure used for sorting the nodes in decreasing order of levels.]

Description []

SideEffects []

SeeAlso []

Definition at line 208 of file utilMem.c.

209 {
210  if ( *pp1 < *pp2 )
211  return -1;
212  if ( *pp1 > *pp2 )
213  return 1;
214  return 0;
215 }
void* Util_MemRecAlloc ( void *  pMem)

BASIC TYPES ///.

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

Synopsis [Remembers an allocated pointer.]

Description []

SideEffects []

SeeAlso []

Definition at line 172 of file utilMem.c.

173 {
174  if ( s_vAllocs )
175  Vec_MemPush( (Vec_Mem_t *)s_vAllocs, pMem );
176  return pMem;
177 }
typedefABC_NAMESPACE_IMPL_START struct Vec_Mem_t_ Vec_Mem_t
DECLARATIONS ///.
Definition: utilMem.c:35
void * s_vAllocs
INCLUDES ///.
Definition: utilMem.c:43
static void Vec_MemPush(Vec_Mem_t *p, void *Entry)
Definition: utilMem.c:129
void* Util_MemRecFree ( void *  pMem)

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

Synopsis [Remembers a deallocated pointer.]

Description []

SideEffects []

SeeAlso []

Definition at line 190 of file utilMem.c.

191 {
192  if ( s_vFrees )
193  Vec_MemPush( (Vec_Mem_t *)s_vFrees, pMem );
194  return pMem;
195 }
typedefABC_NAMESPACE_IMPL_START struct Vec_Mem_t_ Vec_Mem_t
DECLARATIONS ///.
Definition: utilMem.c:35
static void Vec_MemPush(Vec_Mem_t *p, void *Entry)
Definition: utilMem.c:129
void * s_vFrees
Definition: utilMem.c:44
int Util_MemRecIsSet ( )

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

Synopsis [Starts memory structures.]

Description []

SideEffects []

SeeAlso []

Definition at line 330 of file utilMem.c.

331 {
332  return s_vAllocs != NULL && s_vFrees != NULL;
333 }
void * s_vAllocs
INCLUDES ///.
Definition: utilMem.c:43
void * s_vFrees
Definition: utilMem.c:44
void Util_MemRecQuit ( )

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

Synopsis [Quits memory structures.]

Description []

SideEffects []

SeeAlso []

Definition at line 312 of file utilMem.c.

313 {
314  assert( s_vAllocs != NULL && s_vFrees != NULL );
317 }
typedefABC_NAMESPACE_IMPL_START struct Vec_Mem_t_ Vec_Mem_t
DECLARATIONS ///.
Definition: utilMem.c:35
void * s_vAllocs
INCLUDES ///.
Definition: utilMem.c:43
static void Vec_MemFree(Vec_Mem_t *p)
Definition: utilMem.c:93
#define assert(ex)
Definition: util_old.h:213
void * s_vFrees
Definition: utilMem.c:44
void Util_MemRecRecycle ( )

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

Synopsis [Recycles the accumulated memory.]

Description []

SideEffects []

SeeAlso []

Definition at line 272 of file utilMem.c.

273 {
274  Vec_Mem_t * vMerge;
275  assert( s_vAllocs == NULL );
276  assert( s_vFrees == NULL );
280  Vec_MemFree( vMerge );
281 }
int Util_ComparePointers(void **pp1, void **pp2)
Definition: utilMem.c:208
typedefABC_NAMESPACE_IMPL_START struct Vec_Mem_t_ Vec_Mem_t
DECLARATIONS ///.
Definition: utilMem.c:35
void * s_vAllocs
INCLUDES ///.
Definition: utilMem.c:43
static Vec_Mem_t * Vec_MemTwoMerge(Vec_Mem_t *vArr1, Vec_Mem_t *vArr2)
Definition: utilMem.c:228
static void Vec_MemFree(Vec_Mem_t *p)
Definition: utilMem.c:93
static void Vec_MemSort(Vec_Mem_t *p, int(*Vec_MemSortCompare)())
Definition: utilMem.c:152
#define assert(ex)
Definition: util_old.h:213
void * s_vFrees
Definition: utilMem.c:44
void Util_MemRecStart ( )

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

Synopsis [Starts memory structures.]

Description []

SideEffects []

SeeAlso []

Definition at line 294 of file utilMem.c.

295 {
296  assert( s_vAllocs == NULL && s_vFrees == NULL );
297  s_vAllocs = Vec_MemAlloc( 1000 );
298  s_vFrees = Vec_MemAlloc( 1000 );
299 }
static Vec_Mem_t * Vec_MemAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: utilMem.c:70
void * s_vAllocs
INCLUDES ///.
Definition: utilMem.c:43
#define assert(ex)
Definition: util_old.h:213
void * s_vFrees
Definition: utilMem.c:44
static Vec_Mem_t* Vec_MemAlloc ( int  nCap)
inlinestatic

FUNCTION DEFINITIONS ///.

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

Synopsis [Allocates a vector with the given capacity.]

Description []

SideEffects []

SeeAlso []

Definition at line 70 of file utilMem.c.

71 {
72  Vec_Mem_t * p;
73  p = ABC_MEM_ALLOC( Vec_Mem_t, 1 );
74  if ( nCap > 0 && nCap < 8 )
75  nCap = 8;
76  p->nSize = 0;
77  p->nCap = nCap;
78  p->pArray = p->nCap? ABC_MEM_ALLOC( void *, p->nCap ) : NULL;
79  return p;
80 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
typedefABC_NAMESPACE_IMPL_START struct Vec_Mem_t_ Vec_Mem_t
DECLARATIONS ///.
Definition: utilMem.c:35
#define ABC_MEM_ALLOC(type, num)
Definition: utilMem.c:47
static void Vec_MemFree ( Vec_Mem_t p)
inlinestatic

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

Synopsis [Frees the vector.]

Description []

SideEffects []

SeeAlso []

Definition at line 93 of file utilMem.c.

94 {
95  ABC_MEM_FREE( p->pArray );
96  ABC_MEM_FREE( p );
97 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
#define ABC_MEM_FREE(obj)
Definition: utilMem.c:50
static void Vec_MemGrow ( Vec_Mem_t p,
int  nCapMin 
)
inlinestatic

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

Synopsis [Resizes the vector to the given capacity.]

Description []

SideEffects []

SeeAlso []

Definition at line 110 of file utilMem.c.

111 {
112  if ( p->nCap >= nCapMin )
113  return;
114  p->pArray = ABC_MEM_REALLOC( void *, p->pArray, nCapMin );
115  p->nCap = nCapMin;
116 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
#define ABC_MEM_REALLOC(type, obj, num)
Definition: utilMem.c:51
static void Vec_MemPush ( Vec_Mem_t p,
void *  Entry 
)
inlinestatic

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 129 of file utilMem.c.

130 {
131  if ( p->nSize == p->nCap )
132  {
133  if ( p->nCap < 16 )
134  Vec_MemGrow( p, 16 );
135  else
136  Vec_MemGrow( p, 2 * p->nCap );
137  }
138  p->pArray[p->nSize++] = Entry;
139 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static void Vec_MemGrow(Vec_Mem_t *p, int nCapMin)
Definition: utilMem.c:110
static void Vec_MemSort ( Vec_Mem_t p,
int(*)()  Vec_MemSortCompare 
)
static

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

Synopsis [Sorting the entries by their integer value.]

Description []

SideEffects []

SeeAlso []

Definition at line 152 of file utilMem.c.

153 {
154  if ( p->nSize < 2 )
155  return;
156  qsort( (void *)p->pArray, p->nSize, sizeof(void *),
157  (int (*)(const void *, const void *)) Vec_MemSortCompare );
158 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static Vec_Mem_t* Vec_MemTwoMerge ( Vec_Mem_t vArr1,
Vec_Mem_t vArr2 
)
inlinestatic

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

Synopsis [Finds entries that do not appear in both lists.]

Description [Assumes that the vectors are sorted in the increasing order.]

SideEffects []

SeeAlso []

Definition at line 228 of file utilMem.c.

229 {
230  Vec_Mem_t * vArr = Vec_MemAlloc( vArr1->nSize + vArr2->nSize );
231  void ** pBeg = vArr->pArray;
232  void ** pBeg1 = vArr1->pArray;
233  void ** pBeg2 = vArr2->pArray;
234  void ** pEnd1 = vArr1->pArray + vArr1->nSize;
235  void ** pEnd2 = vArr2->pArray + vArr2->nSize;
236  while ( pBeg1 < pEnd1 && pBeg2 < pEnd2 )
237  {
238  if ( *pBeg1 == *pBeg2 )
239  pBeg1++, pBeg2++;
240  else if ( *pBeg1 < *pBeg2 )
241  {
242  free( *pBeg1 );
243  *pBeg++ = *pBeg1++;
244  }
245  else
246  assert( 0 );
247 // *pBeg++ = *pBeg2++;
248  }
249  while ( pBeg1 < pEnd1 )
250  *pBeg++ = *pBeg1++;
251 // while ( pBeg2 < pEnd2 )
252 // *pBeg++ = *pBeg2++;
253  assert( pBeg2 >= pEnd2 );
254  vArr->nSize = pBeg - vArr->pArray;
255  assert( vArr->nSize <= vArr->nCap );
256  assert( vArr->nSize >= vArr1->nSize );
257  assert( vArr->nSize >= vArr2->nSize );
258  return vArr;
259 }
VOID_HACK free()
typedefABC_NAMESPACE_IMPL_START struct Vec_Mem_t_ Vec_Mem_t
DECLARATIONS ///.
Definition: utilMem.c:35
static Vec_Mem_t * Vec_MemAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: utilMem.c:70
#define assert(ex)
Definition: util_old.h:213

Variable Documentation

int s_fInterrupt = 0

Definition at line 45 of file utilMem.c.

void* s_vAllocs = NULL

INCLUDES ///.

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

FileName [utilInt.h]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Memory recycling utilities.]

Synopsis [Internal declarations.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

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

Revision [

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

]PARAMETERS ///

Definition at line 43 of file utilMem.c.

void* s_vFrees = NULL

Definition at line 44 of file utilMem.c.