ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/savqstr.c
Revision: 2.2
Committed: Wed Jan 27 20:23:49 1993 UTC (31 years, 3 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.1: +44 -10 lines
Log Message:
blocked calls to bmalloc() to optimize VM usage

File Contents

# Content
1 /* Copyright (c) 1993 Regents of the University of California */
2
3 #ifndef lint
4 static char SCCSid[] = "$SunId$ LBL";
5 #endif
6
7 /*
8 * Save unshared strings, packing them together into
9 * large blocks to optimize paging in VM environments.
10 */
11
12 #define NULL 0
13
14 #ifdef BIGMEM
15 #ifndef MINBLOCK
16 #define MINBLOCK (1<<12) /* minimum allocation block size */
17 #endif
18 #ifndef MAXBLOCK
19 #define MAXBLOCK (1<<16) /* maximum allocation block size */
20 #endif
21 #else
22 #ifndef MINBLOCK
23 #define MINBLOCK (1<<10) /* minimum allocation block size */
24 #endif
25 #ifndef MAXBLOCK
26 #define MAXBLOCK (1<<14) /* maximum allocation block size */
27 #endif
28 #endif
29
30 extern char *bmalloc();
31
32
33 char *
34 savqstr(s) /* save a private string */
35 register char *s;
36 {
37 static char *curp = NULL; /* allocated memory pointer */
38 static unsigned nrem = 0; /* bytes remaining in block */
39 static unsigned nextalloc = MINBLOCK; /* next block size */
40 register char *cp;
41 register unsigned n;
42
43 for (cp = s; *cp++; ) /* compute strlen()+1 */
44 ;
45 if ((n = cp-s) > nrem) { /* do we need more core? */
46 bfree(curp, nrem); /* free remnant */
47 while (n > nextalloc)
48 nextalloc <<= 1;
49 if ((curp = bmalloc(nrem=nextalloc)) == NULL) {
50 eputs("out of memory in savqstr");
51 quit(1);
52 }
53 if ((nextalloc <<= 1) > MAXBLOCK) /* double block size */
54 nextalloc = MAXBLOCK;
55 }
56 for (cp = curp; *cp++ = *s++; ) /* inline strcpy() */
57 ;
58 s = curp; /* update allocation info. */
59 curp = cp;
60 nrem -= n;
61 return(s); /* return new location */
62 }
63
64
65 freeqstr(s) /* free a private string (not recommended) */
66 char *s;
67 {
68 bfree(s, strlen(s)+1);
69 }