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.8 by greg, Thu Oct 8 12:27:02 1992 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 253 | Line 251 | register unsigned  n;
251          n = (n+(BYTES_WORD-1))&~(BYTES_WORD-1);         /* word align rqst. */
252  
253          if (n > nrem) {                                 /* need more core */
254 +        tryagain:
255                  if (n > amnt) {                         /* big chunk */
256                          thisamnt = (n+(pagesz-1))&~(pagesz-1);
257                          if (thisamnt <= MAXINCR)        /* increase amnt */
# Line 261 | Line 260 | register unsigned  n;
260                          thisamnt = amnt;
261                  p = sbrk(thisamnt);
262                  if ((int)p == -1) {                     /* uh-oh, ENOMEM */
263 <                        thisamnt = n;                   /* search free lists */
264 <                        p = mscrounge(&thisamnt);
265 <                        if (p == NULL)                  /* we're really out */
263 >                        errno = 0;                      /* call cavalry */
264 >                        if (thisamnt >= n+pagesz) {
265 >                                amnt = pagesz;          /* minimize request */
266 >                                goto tryagain;
267 >                        }
268 >                        thisamnt = n;
269 >                        p = mscrounge(&thisamnt);       /* search free lists */
270 >                        if (p == NULL) {                /* we're really out */
271 >                                errno = ENOMEM;
272                                  return(NULL);
273 +                        }
274                  }
275   #ifdef MSTATS
276                  else b_nsbrked += thisamnt;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines