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.10 by greg, Fri Nov 10 17:04:15 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 > #endif
31  
32   #ifdef MSTATS
33   #include  <stdio.h>
# Line 156 | Line 159 | unsigned       *np;
159  
160          for ( ; ; ) {
161                                          /* compact free lists */
162 <                compactfree();
162 >                while (compactfree())
163 >                        ;
164                                          /* find largest block */
165                  tab = mtab(&cptab); tablen = mtablen(&cptab);
166                  big = tab;
# Line 169 | Line 173 | unsigned       *np;
173                          big->siz = 0;           /* remove from table */
174                          return(big->ptr);       /* return it */
175                  }
176 <                if (mtablen(big) < tablen+1) {
176 >                if (mtablen(big) <= tablen) {
177                          *np = 0;                /* cannot grow table */
178                          return(NULL);           /* report failure */
179                  }
# Line 179 | Line 183 | unsigned       *np;
183                  cptab.ptr = big->ptr;
184                  cptab.siz = big->siz;
185                  big->siz = 0;                   /* clear and copy */
182 #ifdef BSD
186                  bcopy((char *)tab, (char *)(mtab(&cptab)+1),
187                                  tablen*sizeof(struct mblk));
188                  bzero((char *)(mtab(&cptab)+tablen+1),
189                          (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
190          }                       /* next round */
191   }
192   #endif          /* MCOMP */
# Line 254 | 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 262 | 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;
# Line 380 | Line 385 | unsigned       n;
385          if ((p = malloc(n)) == NULL)
386                  return(n<=on ? op : NULL);
387          if (on) {
383 #ifdef  BSD
388                  bcopy(op, p, n>on ? on : n);
385 #else
386                (void)memcpy(p, op, n>on ? on : n);
387 #endif
389                  free(op);
390          }
391          return(p);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines