--- ray/src/common/bmalloc.c 2004/10/23 18:55:52 2.9 +++ ray/src/common/bmalloc.c 2025/04/12 01:43:53 2.10 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: bmalloc.c,v 2.9 2004/10/23 18:55:52 schorsch Exp $"; +static const char RCSid[] = "$Id: bmalloc.c,v 2.10 2025/04/12 01:43:53 greg Exp $"; #endif /* * Bmalloc provides basic memory allocation without overhead (no free lists). @@ -17,28 +17,28 @@ static const char RCSid[] = "$Id: bmalloc.c,v 2.9 2004 #include "rtmisc.h" -#ifndef MBLKSIZ -#define MBLKSIZ 16376 /* size of memory allocation block */ -#endif -#define WASTEFRAC 12 /* don't waste more than a fraction */ #ifndef ALIGNT #define ALIGNT double /* type for alignment */ #endif #define BYTES_WORD sizeof(ALIGNT) +#ifndef MBLKSIZ /* size of memory allocation block */ +#define MBLKSIZ ((1<<15)-BYTES_WORD) +#endif +#define WASTEFRAC 12 /* don't waste more than a fraction */ + static char *bposition = NULL; static size_t nremain = 0; - void * -bmalloc( /* allocate a block of n bytes */ -register size_t n +bmalloc( /* quickly allocate a block of n bytes */ +size_t n ) { - if (n > nremain && (n > MBLKSIZ || nremain > MBLKSIZ/WASTEFRAC)) + if ((n > nremain) & ((n > MBLKSIZ) | (nremain > MBLKSIZ/WASTEFRAC))) return(malloc(n)); /* too big */ - n = (n+(BYTES_WORD-1))&~(BYTES_WORD-1); /* word align */ + n = (n+(BYTES_WORD-1)) & ~(BYTES_WORD-1); /* word align */ if (n > nremain && (bposition = malloc(nremain = MBLKSIZ)) == NULL) { nremain = 0; @@ -49,15 +49,14 @@ register size_t n return(bposition - n); } - void -bfree( /* free random memory */ -register void *pp, -register size_t n +bfree( /* free some memory; anything in process space */ +void *pp, +size_t n ) { - register char *p = pp; - register size_t bsiz; + char *p = pp; + size_t bsiz; /* check alignment */ bsiz = BYTES_WORD - ((size_t)p&(BYTES_WORD-1)); if (bsiz < BYTES_WORD) {