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 2.6 by greg, Fri Sep 4 09:57:43 1992 UTC vs.
Revision 2.9 by greg, Tue Oct 24 09:45:07 1995 UTC

# Line 24 | Line 24 | static char SCCSid[] = "$SunId$ LBL";
24  
25   #include  <errno.h>
26  
27 < extern int      errno;
27 > #ifndef  BSD
28 > #define  bcopy(s,d,n)           (void)memcpy(d,s,n)
29 > #define  bzero(d,n)             (void)memset(d,0,n)
30 > extern char  *memcpy(), *memset();
31 > #endif
32  
33   #ifdef MSTATS
34   #include  <stdio.h>
# Line 156 | Line 160 | unsigned       *np;
160  
161          for ( ; ; ) {
162                                          /* compact free lists */
163 <                compactfree();
163 >                while (compactfree())
164 >                        ;
165                                          /* find largest block */
166                  tab = mtab(&cptab); tablen = mtablen(&cptab);
167                  big = tab;
# Line 169 | Line 174 | unsigned       *np;
174                          big->siz = 0;           /* remove from table */
175                          return(big->ptr);       /* return it */
176                  }
177 <                if (mtablen(big) < tablen+1) {
177 >                if (mtablen(big) <= tablen) {
178                          *np = 0;                /* cannot grow table */
179                          return(NULL);           /* report failure */
180                  }
# Line 179 | Line 184 | unsigned       *np;
184                  cptab.ptr = big->ptr;
185                  cptab.siz = big->siz;
186                  big->siz = 0;                   /* clear and copy */
182 #ifdef BSD
187                  bcopy((char *)tab, (char *)(mtab(&cptab)+1),
188                                  tablen*sizeof(struct mblk));
189                  bzero((char *)(mtab(&cptab)+tablen+1),
190                          (mtablen(&cptab)-tablen-1)*sizeof(struct mblk));
187 #else
188                (void)memcpy((char *)(mtab(&cptab)+1), (char *)tab,
189                                tablen*sizeof(struct mblk));
190                memset((char *)(mtab(&cptab)+tablen+1), 0,
191                        (mtablen(&cptab)-tablen-1)*sizeof(struct mblk));
192 #endif
191          }                       /* next round */
192   }
193   #endif          /* MCOMP */
# Line 254 | Line 252 | register unsigned  n;
252          n = (n+(BYTES_WORD-1))&~(BYTES_WORD-1);         /* word align rqst. */
253  
254          if (n > nrem) {                                 /* need more core */
255 +        tryagain:
256                  if (n > amnt) {                         /* big chunk */
257                          thisamnt = (n+(pagesz-1))&~(pagesz-1);
258                          if (thisamnt <= MAXINCR)        /* increase amnt */
# Line 262 | Line 261 | register unsigned  n;
261                          thisamnt = amnt;
262                  p = sbrk(thisamnt);
263                  if ((int)p == -1) {                     /* uh-oh, ENOMEM */
264 <                        thisamnt = n;                   /* search free lists */
265 <                        p = mscrounge(&thisamnt);
266 <                        if (p == NULL)                  /* we're really out */
264 >                        errno = 0;                      /* call cavalry */
265 >                        if (thisamnt >= n+pagesz) {
266 >                                amnt = pagesz;          /* minimize request */
267 >                                goto tryagain;
268 >                        }
269 >                        thisamnt = n;
270 >                        p = mscrounge(&thisamnt);       /* search free lists */
271 >                        if (p == NULL) {                /* we're really out */
272 >                                errno = ENOMEM;
273                                  return(NULL);
274 +                        }
275                  }
276   #ifdef MSTATS
277                  else b_nsbrked += thisamnt;
# Line 380 | Line 386 | unsigned       n;
386          if ((p = malloc(n)) == NULL)
387                  return(n<=on ? op : NULL);
388          if (on) {
383 #ifdef  BSD
389                  bcopy(op, p, n>on ? on : n);
385 #else
386                (void)memcpy(p, op, n>on ? on : n);
387 #endif
390                  free(op);
391          }
392          return(p);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines