Back to index

radiance  4R0+20100331
Defines | Functions | Variables
bmalloc.c File Reference
#include "copyright.h"
#include <stdlib.h>
#include "rtmisc.h"

Go to the source code of this file.

Defines

#define MBLKSIZ   16376 /* size of memory allocation block */
#define WASTEFRAC   12 /* don't waste more than a fraction */
#define ALIGNT   double /* type for alignment */
#define BYTES_WORD   sizeof(ALIGNT)

Functions

void * bmalloc (register size_t n)
void bfree (register void *pp, register size_t n)

Variables

static const char RCSid [] = "$Id: bmalloc.c,v 2.9 2004/10/23 18:55:52 schorsch Exp $"
static char * bposition = NULL
static size_t nremain = 0

Define Documentation

#define ALIGNT   double /* type for alignment */

Definition at line 25 of file bmalloc.c.

#define BYTES_WORD   sizeof(ALIGNT)

Definition at line 27 of file bmalloc.c.

#define MBLKSIZ   16376 /* size of memory allocation block */

Definition at line 21 of file bmalloc.c.

#define WASTEFRAC   12 /* don't waste more than a fraction */

Definition at line 23 of file bmalloc.c.


Function Documentation

void bfree ( register void *  pp,
register size_t  n 
)

Definition at line 54 of file bmalloc.c.

{
       register char *p = pp;
       register size_t      bsiz;
                                   /* check alignment */
       bsiz = BYTES_WORD - ((size_t)p&(BYTES_WORD-1));
       if (bsiz < BYTES_WORD) {
              p += bsiz;
              n -= bsiz;
       }
       if (p + n == bposition) {   /* just allocated? */
              bposition = p;
              nremain += n;
              return;
       }
       if (n > nremain) {          /* better than what we've got? */
              bposition = p;
              nremain = n;
              return;
       }
                            /* just throw it away, then */
}

Here is the caller graph for this function:

void* bmalloc ( register size_t  n)

Definition at line 34 of file bmalloc.c.

{
       if (n > nremain && (n > MBLKSIZ || nremain > MBLKSIZ/WASTEFRAC))
              return(malloc(n));                 /* too big */

       n = (n+(BYTES_WORD-1))&~(BYTES_WORD-1);          /* word align */

       if (n > nremain && (bposition = malloc(nremain = MBLKSIZ)) == NULL) {
              nremain = 0;
              return(NULL);
       }
       bposition += n;
       nremain -= n;
       return(bposition - n);
}

Here is the caller graph for this function:


Variable Documentation

char* bposition = NULL [static]

Definition at line 29 of file bmalloc.c.

size_t nremain = 0 [static]

Definition at line 30 of file bmalloc.c.

const char RCSid[] = "$Id: bmalloc.c,v 2.9 2004/10/23 18:55:52 schorsch Exp $" [static]

Definition at line 2 of file bmalloc.c.