ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/bmalloc.c
Revision: 1.1
Committed: Tue Sep 25 18:56:04 1990 UTC (33 years, 7 months ago) by greg
Content type: text/plain
Branch: MAIN
Log Message:
Initial revision

File Contents

# User Rev Content
1 greg 1.1 /* Copyright (c) 1990 Regents of the University of California */
2    
3     #ifndef lint
4     static char SCCSid[] = "$SunId$ LBL";
5     #endif
6    
7     /*
8     * Simple memory allocation without overhead
9     *
10     */
11    
12     #ifndef MBLKSIZ
13     #define MBLKSIZ 16376 /* size of memory allocation block */
14     #endif
15     #ifndef ALIGN
16     #define ALIGN int /* type for alignment */
17     #endif
18     #define BYTES_WORD sizeof(ALIGN)
19    
20    
21     char *
22     bmalloc(n) /* allocate a block of n bytes, no refunds */
23     register unsigned n;
24     {
25     static char *bpos = NULL;
26     static unsigned nrem = 0;
27    
28     if (n > MBLKSIZ/2) /* too big for me */
29     return(malloc(n));
30    
31     n = (n+(BYTES_WORD-1))&~(BYTES_WORD-1); /* word align */
32    
33     if (n > nrem) {
34     if ((bpos = malloc((unsigned)MBLKSIZ)) == NULL) {
35     nrem = 0;
36     return(NULL);
37     }
38     nrem = MBLKSIZ;
39     }
40     bpos += n;
41     nrem -= n;
42     return(bpos - n);
43     }
44    
45    
46     bfree(p, n) /* free random memory */
47     char *p;
48     unsigned n;
49     {
50     /* not implemented */
51     }