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.7 by greg, Fri Sep 4 18:36:05 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;
28
27   #ifndef  BSD
28   #define  bcopy(s,d,n)           (void)memcpy(d,s,n)
29   #define  bzero(d,n)             (void)memset(d,0,n)
# Line 162 | 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 253 | 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 261 | 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;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines