ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/malloc.c
(Generate patch)

Comparing ray/src/common/malloc.c (file contents):
Revision 1.8 by greg, Wed Oct 3 16:20:38 1990 UTC vs.
Revision 1.9 by greg, Wed Oct 3 21:01:59 1990 UTC

# Line 21 | Line 21 | static char SCCSid[] = "$SunId$ LBL";
21  
22   #include  <errno.h>
23  
24 + #ifdef MSTATS
25 + #include  <stdio.h>
26 +
27 + static unsigned b_nalloced = 0;
28 + static unsigned b_nfreed = 0;
29 + static unsigned b_nscrounged = 0;
30 + static unsigned m_nalloced = 0;
31 + static unsigned m_nfreed = 0;
32 + static unsigned m_nwasted = 0;
33 + #else
34   #define  NULL           0
35 + #endif
36  
37   #ifndef ALIGN
38   #define  ALIGN          int                     /* align type */
39   #endif
40   #define  BYTES_WORD     sizeof(ALIGN)
41  
42 < #define  MAXINCR        (1<<18)                 /* largest sbrk(2) increment */
42 > #define  MAXINCR        (1<<16)                 /* largest sbrk(2) increment */
43  
44   #ifdef  NOVMEM
45   #define  getpagesize()  BYTES_WORD
# Line 60 | Line 71 | register unsigned      *np;
71                          *np = bsiz+sizeof(M_HEAD);
72                          p = (char *)free_list[bucket];
73                          free_list[bucket] = free_list[bucket]->next;
74 + #ifdef MSTATS
75 +                        b_nscrounged += *np;
76 + #endif
77                          return(p);
78                  }
79          *np = 0;
# Line 79 | Line 93 | register unsigned  n;
93          unsigned  thisamnt;
94          register char   *p;
95  
96 + #ifdef MSTATS
97 +        b_nalloced += n;
98 + #endif
99          if (pagesz == 0) {                              /* initialize */
100                  pagesz = amnt = getpagesize();
101                  nrem = (int)sbrk(0);                    /* page align break */
# Line 124 | Line 141 | register unsigned  n;
141   {
142          register int    bucket;
143          register unsigned       bsiz;
144 +
145 + #ifdef MSTATS
146 +        b_nfreed += n;
147 + #endif
148                                          /* align pointer */
149          bsiz = BYTES_WORD - ((unsigned)p&(BYTES_WORD-1));
150          if (bsiz < BYTES_WORD) {
# Line 159 | Line 180 | unsigned       n;
180                  errno = EINVAL;
181                  return(NULL);
182          }
183 + #ifdef MSTATS
184 +        m_nalloced += bsiz + sizeof(M_HEAD);
185 +        m_nwasted += bsiz + sizeof(M_HEAD) - n;
186 + #endif
187          if (free_list[bucket] == NULL) {        /* need more core */
188                  mp = (M_HEAD *)bmalloc(bsiz+sizeof(M_HEAD));
189                  if (mp == NULL)
# Line 210 | Line 235 | char   *p;
235          bucket = mp->bucket;
236          mp->next = free_list[bucket];
237          free_list[bucket] = mp;
238 + #ifdef MSTATS
239 +        m_nfreed += (1 << bucket) + sizeof(M_HEAD);
240 + #endif
241   }
242  
243  
# Line 225 | Line 253 | getpagesize()                  /* use SYSV var structure to get page
253          return(1 << v.v_pageshift);
254   }
255   #endif
256 + #endif
257 +
258 +
259 + #ifdef MSTATS
260 + printmemstats(fp)               /* print memory statistics to stream */
261 + FILE    *fp;
262 + {
263 +        register int    i;
264 +        int     n;
265 +        register M_HEAD *mp;
266 +        unsigned int    total = 0;
267 +
268 +        fprintf(fp, "Memory statistics:\n");
269 +        fprintf(fp, "\tbmalloc: %d bytes allocated\n", b_nalloced);
270 +        fprintf(fp, "\tbmalloc: %d bytes freed\n", b_nfreed);
271 +        fprintf(fp, "\tbmalloc: %d bytes scrounged\n", b_nscrounged);
272 +        fprintf(fp, "\tmalloc: %d bytes allocated\n", m_nalloced);
273 +        fprintf(fp, "\tmalloc: %d bytes wasted (%.1f%%)\n", m_nwasted,
274 +                        100.0*m_nwasted/m_nalloced);
275 +        fprintf(fp, "\tmalloc: %d bytes freed\n", m_nfreed);
276 +        for (i = NBUCKETS-1; i >= FIRSTBUCKET; i--) {
277 +                n = 0;
278 +                for (mp = free_list[i]; mp != NULL; mp = mp->next)
279 +                        n++;
280 +                if (n) {
281 +                        fprintf(fp, "\t%d * %u\n", n, 1<<i);
282 +                        total += n * ((1<<i) + sizeof(M_HEAD));
283 +                }
284 +        }
285 +        fprintf(fp, "\t %u total bytes in free list\n", total);
286 + }
287   #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines