abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ivyMem.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [ivyMem.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [And-Inverter Graph package.]
8 
9  Synopsis [Memory management for the AIG nodes.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - May 11, 2006.]
16 
17  Revision [$Id: ivyMem.c,v 1.00 2006/05/11 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "ivy.h"
22 
24 
25 
26 ////////////////////////////////////////////////////////////////////////
27 /// DECLARATIONS ///
28 ////////////////////////////////////////////////////////////////////////
29 
30 // memory management
31 #define IVY_PAGE_SIZE 12 // page size containing 2^IVY_PAGE_SIZE nodes
32 #define IVY_PAGE_MASK 4095 // page bitmask (2^IVY_PAGE_SIZE)-1
33 
34 ////////////////////////////////////////////////////////////////////////
35 /// FUNCTION DEFINITIONS ///
36 ////////////////////////////////////////////////////////////////////////
37 
38 /**Function*************************************************************
39 
40  Synopsis [Starts the internal memory manager.]
41 
42  Description []
43 
44  SideEffects []
45 
46  SeeAlso []
47 
48 ***********************************************************************/
50 {
51  p->vChunks = Vec_PtrAlloc( 128 );
52  p->vPages = Vec_PtrAlloc( 128 );
53 }
54 
55 /**Function*************************************************************
56 
57  Synopsis [Stops the internal memory manager.]
58 
59  Description []
60 
61  SideEffects []
62 
63  SeeAlso []
64 
65 ***********************************************************************/
67 {
68  void * pMemory;
69  int i;
70  Vec_PtrForEachEntry( void *, p->vChunks, pMemory, i )
71  ABC_FREE( pMemory );
72  Vec_PtrFree( p->vChunks );
73  Vec_PtrFree( p->vPages );
74  p->pListFree = NULL;
75 }
76 
77 /**Function*************************************************************
78 
79  Synopsis [Allocates additional memory for the nodes.]
80 
81  Description [Allocates IVY_PAGE_SIZE nodes. Aligns memory by 32 bytes.
82  Records the pointer to the AIG manager in the -1 entry.]
83 
84  SideEffects []
85 
86  SeeAlso []
87 
88 ***********************************************************************/
90 {
91  char * pMemory;
92  int i, nBytes;
93  int EntrySizeMax = 128;
94  assert( sizeof(Ivy_Obj_t) <= EntrySizeMax );
95  assert( p->pListFree == NULL );
96 // assert( (Ivy_ManObjNum(p) & IVY_PAGE_MASK) == 0 );
97  // allocate new memory page
98  nBytes = sizeof(Ivy_Obj_t) * (1<<IVY_PAGE_SIZE) + EntrySizeMax;
99  pMemory = ABC_ALLOC( char, nBytes );
100  Vec_PtrPush( p->vChunks, pMemory );
101  // align memory at the 32-byte boundary
102  pMemory = pMemory + EntrySizeMax - (((int)(ABC_PTRUINT_T)pMemory) & (EntrySizeMax-1));
103  // remember the manager in the first entry
104  Vec_PtrPush( p->vPages, pMemory );
105  // break the memory down into nodes
106  p->pListFree = (Ivy_Obj_t *)pMemory;
107  for ( i = 1; i <= IVY_PAGE_MASK; i++ )
108  {
109  *((char **)pMemory) = pMemory + sizeof(Ivy_Obj_t);
110  pMemory += sizeof(Ivy_Obj_t);
111  }
112  *((char **)pMemory) = NULL;
113 }
114 
115 ////////////////////////////////////////////////////////////////////////
116 /// END OF FILE ///
117 ////////////////////////////////////////////////////////////////////////
118 
119 
121 
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
void Ivy_ManStopMemory(Ivy_Man_t *p)
Definition: ivyMem.c:66
#define IVY_PAGE_MASK
Definition: ivyMem.c:32
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
Definition: ivy.h:73
#define IVY_PAGE_SIZE
DECLARATIONS ///.
Definition: ivyMem.c:31
void Ivy_ManStartMemory(Ivy_Man_t *p)
FUNCTION DEFINITIONS ///.
Definition: ivyMem.c:49
typedefABC_NAMESPACE_HEADER_START struct Ivy_Man_t_ Ivy_Man_t
INCLUDES ///.
Definition: ivy.h:46
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
#define ABC_FREE(obj)
Definition: abc_global.h:232
void Ivy_ManAddMemory(Ivy_Man_t *p)
Definition: ivyMem.c:89
struct Ivy_Obj_t_ Ivy_Obj_t
Definition: ivy.h:47
#define assert(ex)
Definition: util_old.h:213
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223