Main Page | Alphabetical List | Class List | File List | Class Members | File Members

alloc.c

Go to the documentation of this file.
00001 #define       NULL 0
00002 #include "bary.h"
00003 #include <stdio.h>
00004 #include <stdlib.h>
00005 
00007 /*--------------------------------------------------------------------*/
00008 
00009 /*  Memory Management for DLLIST objects 
00010  *  ====================================
00011  */
00012 
00013 /*  To have a good layout, we calculate the number of crossings of edges
00014  *  and try to minimize them. For the calculation of crossings, we need
00015  *  double linked lists of nodes (see step2.c) representing the upper
00016  *  list of touched nodes and the lower list of touched nodes. Because
00017  *  nodes may have multible occurences in these lists, we use the special
00018  *  data structure DLLIST. 
00019  *  We reuse the DSUCC field to keep the list of free dllist nodes.
00020  *  But THIS dllist_freelist is NOT double linked.
00021  */
00022 
00023 static DLLIST   dllist_freelist  = NULL;     /* list of free dllist nodes */
00024 
00025 
00026 /*  Allocate a DLLIST object
00027  *  ------------------------
00028  *  First, we look in the free list, if we have a free cell. Otherwise,
00029  *  we allocate a cell from the core memory.
00030  *  The successor is always NULL, because we append at the end of the
00031  *  list. pred is the predecessor.
00032  */
00033 
00034 
00035 #ifdef ANSI_C
00036 DLLIST  dllist_alloc(GNODE node, DLLIST pred)
00037 #else
00038 DLLIST  dllist_alloc(node,pred)
00039 GNODE  node;
00040 DLLIST pred;
00041 #endif
00042 {
00043         DLLIST  h;
00044 
00045         debugmessage("dllist_alloc","");
00046         if (dllist_freelist) {
00047                 h = dllist_freelist;
00048                 dllist_freelist = DSUCC(dllist_freelist);
00049         }
00050         else    h = (DLLIST)myalloc(sizeof(struct dllist));
00051         DNODE(h) = node;
00052         DPRED(h) = pred;
00053         DSUCC(h) = NULL;
00054         return(h);
00055 }
00056 
00057 
00058 /*  Deallocate one DLLIST objects
00059  *  -----------------------------
00060  *  The crossing algorithm is stable enough such that after calculation
00061  *  of crossings all DLLIST elements are given free by this function.
00062  *  Thus we don't need any additional memory management.
00063  */
00064 
00065 #ifdef ANSI_C
00066 void    dllist_free(DLLIST x)
00067 #else
00068 void    dllist_free(x)
00069 DLLIST x;
00070 #endif
00071 {
00072         debugmessage("dllist_free","");
00073         DSUCC(x) = dllist_freelist;
00074         dllist_freelist = x;
00075 }
00076 
00077 
00078 /*  Deallocate a list of DLLIST objects
00079  *  -----------------------------------
00080  */
00081 
00082 #ifdef ANSI_C
00083 void    dllist_free_all(DLLIST x)
00084 #else
00085 void    dllist_free_all(x)
00086 DLLIST x;
00087 #endif
00088 {
00089         DLLIST h;
00090 
00091         debugmessage("dllist_free","");
00092         if (x) {
00093                 h = x;
00094                 while (DSUCC(h)) h = DSUCC(h);
00095                 DSUCC(h) = dllist_freelist;
00096                 dllist_freelist = x;
00097         }
00098 }
00099 
00100 
00101 
00102 void * myalloc(unsigned size)
00103 {
00104     return malloc(size);
00105 }
00106 
00107 
00108 /*  Allocate a temporary GNLIST object
00109  *  ----------------------------------
00110  *  First, we look in the free list, if we have a free node. Otherwise,
00111  *  we allocate a node from the core memory.
00112  *  We also set some default values.
00113  *  These node lists are temporary, thus we store them in the
00114  *  tmpnconslist, to give them free later.
00115  */
00116 static GNLIST ncons_freelist = NULL;  /* list of free cons cells      */
00117 static GNLIST tmpnconslist   = NULL;  /* list of allocated cons cells */
00118 
00119 GNLIST  tmpnodelist_alloc(void)
00120 {
00121         GNLIST  h;
00122 
00123         debugmessage("tmpnodelist_alloc","");
00124         if (ncons_freelist) {
00125                 h = ncons_freelist;
00126                 ncons_freelist = GNINTERN(ncons_freelist);
00127         }
00128         else    h = (GNLIST)myalloc(sizeof(struct gnlist));
00129         GNINTERN(h) = tmpnconslist;
00130         GNNODE(h)   = NULL;
00131         GNNEXT(h)   = NULL;
00132         tmpnconslist = h;
00133         return(h);
00134 }
00135 

Generated on Sat Aug 6 11:49:18 2005 for VCGIntrospector by doxygen 1.3.6