abc/src/bdd/cudd/cuddReorder.c
/**Function********************************************************************

  Synopsis    [Dynamically allocates a Node.]

  Description [Dynamically allocates a Node. This procedure is similar
  to cuddAllocNode in Cudd_Table.c, but it does not attempt garbage
  collection, because during reordering there are no dead nodes.
  Returns a pointer to a new node if successful; NULL is memory is
  full.]

  SideEffects [None]

  SeeAlso     [cuddAllocNode]

******************************************************************************/
Function
Synopsis    [Dynamically allocates a Node.]

Description [Dynamically allocates a Node. This procedure is similar
to cuddAllocNode in Cudd_Table.c, but it does not attempt garbage
collection, because during reordering there are no dead nodes.
Returns a pointer to a new node if successful; NULL is memory is
full.]




Function Synopsis [ Dynamically allocates a Node . ] Description [ Dynamically allocates a Node . This procedure is similar to cuddAllocNode in Cudd_Table . c but it does not attempt garbage collection because during reordering there are no dead nodes . Returns a pointer to a new node if successful ; NULL is memory is full . ]
DdNode *
cuddDynamicAllocNode(
  DdManager * table)
{
    int     i;
    DdNodePtr *mem;
    DdNode *list, *node;
    extern DD_OOMFP MMoutOfMemory;
    DD_OOMFP saveHandler;
    if (table->nextFree == NULL) {        
        saveHandler = MMoutOfMemory;
        MMoutOfMemory = Cudd_OutOfMem;
        mem = (DdNodePtr *) ABC_ALLOC(DdNode, DD_MEM_CHUNK + 2);
        MMoutOfMemory = saveHandler;
        if (mem == NULL && table->stash != NULL) {
            ABC_FREE(table->stash);
            table->stash = NULL;
            table->maxCacheHard = table->cacheSlots - 1;
            table->cacheSlack = - (int) (table->cacheSlots + 1);
            for (i = 0; i < table->size; i++) {
                table->subtables[i].maxKeys <<= 2;
            }
            mem = (DdNodePtr *) ABC_ALLOC(DdNode,DD_MEM_CHUNK + 2);
        }
        if (mem == NULL) {
            (*MMoutOfMemory)(sizeof(DdNode)*(DD_MEM_CHUNK + 1));
            table->errorCode = CUDD_MEMORY_OUT;
#ifdef DD_VERBOSE
            (void) fprintf(table->err,
                           "cuddDynamicAllocNode: out of memory");
            (void) fprintf(table->err,"Memory in use = %lu\n",
                           table->memused);
#endif
            return(NULL);
        } else {        
            unsigned long offset;
            table->memused += (DD_MEM_CHUNK + 1) * sizeof(DdNode);
            mem[0] = (DdNode *) table->memoryList;
            table->memoryList = mem;
            offset = (unsigned long) mem & (32 - 1);
            mem += (32 - offset) / sizeof(DdNodePtr);
#ifdef DD_DEBUG
            assert(((unsigned long) mem & (32 - 1)) == 0);
#endif
            list = (DdNode *) mem;
            i = 1;
            do {
                list[i - 1].ref = 0;
                list[i - 1].next = &list[i];
            } while (++i < DD_MEM_CHUNK);
            list[DD_MEM_CHUNK-1].ref = 0;
            list[DD_MEM_CHUNK - 1].next = NULL;
            table->nextFree = &list[0];
        }
    } 
    node = table->nextFree;
    table->nextFree = node->next;
    node->Id = 0;
    return (node);
}
DdNode * cuddDynamicAllocNode ( DdManager * table ) { int i ; DdNodePtr * mem ; DdNode * list , * node ; extern DD_OOMFP MMoutOfMemory ; DD_OOMFP saveHandler ; if ( table -> nextFree == NULL ) { saveHandler = MMoutOfMemory ; MMoutOfMemory = Cudd_OutOfMem ; mem = ( DdNodePtr * ) ABC_ALLOC ( DdNode , DD_MEM_CHUNK + 2 ) ; MMoutOfMemory = saveHandler ; if ( mem == NULL && table -> stash != NULL ) { ABC_FREE ( table -> stash ) ; table -> stash = NULL ; table -> maxCacheHard = table -> cacheSlots - 1 ; table -> cacheSlack = - ( int ) ( table -> cacheSlots + 1 ) ; for ( i = 0 ; i < table -> size ; i ++ ) { table -> subtables [ i ] . maxKeys <<= 2 ; } mem = ( DdNodePtr * ) ABC_ALLOC ( DdNode , DD_MEM_CHUNK + 2 ) ; } if ( mem == NULL ) { ( * MMoutOfMemory ) ( sizeof ( DdNode ) * ( DD_MEM_CHUNK + 1 ) ) ; table -> errorCode = CUDD_MEMORY_OUT ; #ifdef DD_VERBOSE ( void ) fprintf ( table -> err , " " ) ; ( void ) fprintf ( table -> err , " \n " , table -> memused ) ; #endif return ( NULL ) ; } else { unsigned long offset ; table -> memused += ( DD_MEM_CHUNK + 1 ) * sizeof ( DdNode ) ; mem [ 0 ] = ( DdNode * ) table -> memoryList ; table -> memoryList = mem ; offset = ( unsigned long ) mem & ( 32 - 1 ) ; mem += ( 32 - offset ) / sizeof ( DdNodePtr ) ; #ifdef DD_DEBUG assert ( ( ( unsigned long ) mem & ( 32 - 1 ) ) == 0 ) ; #endif list = ( DdNode * ) mem ; i = 1 ; do { list [ i - 1 ] . ref = 0 ; list [ i - 1 ] . next = & list [ i ] ; } while ( ++ i < DD_MEM_CHUNK ) ; list [ DD_MEM_CHUNK - 1 ] . ref = 0 ; list [ DD_MEM_CHUNK - 1 ] . next = NULL ; table -> nextFree = & list [ 0 ] ; } } node = table -> nextFree ; table -> nextFree = node -> next ; node -> Id = 0 ; return ( node ) ; }
Function
Synopsis    [Dynamically allocates a Node.]
Function Synopsis [ Dynamically allocates a Node . ]
/* free list is empty */ /* Try to allocate a new block. */ //        mem = (DdNodePtr *) ABC_ALLOC(DdNode, DD_MEM_CHUNK + 1); /* Inhibit resizing of tables. */ //            mem = (DdNodePtr *) ABC_ALLOC(DdNode,DD_MEM_CHUNK + 1); /* Out of luck. Call the default handler to do
            ** whatever it specifies for a failed malloc.  If this
            ** handler returns, then set error code, print
            ** warning, and return. */ /* successful allocation; slice memory */ /* Here we rely on the fact that the size of a DdNode is a
            ** power of 2 and a multiple of the size of a pointer.
            ** If we align one node, all the others will be aligned
            ** as well. */ //            offset = (unsigned long) mem & (sizeof(DdNode) - 1); //            mem += (sizeof(DdNode) - offset) / sizeof(DdNodePtr); //            assert(((unsigned long) mem & (sizeof(DdNode) - 1)) == 0); /* if free list empty */