4 * Allocated string storage module.
6 * 31-Oct-1997 by John Hartman
16 * Allocate space for "str", copy str into new space
17 * Return a pointer to the allocated name, or NULL if out of memory
19 char *StoreString( char *str )
21 /* To avoid wasting memory headers on small allocations, we
22 / allocate a big chunk and parcel it out as required.
23 / These static variables remember our hunk
25 #define STR_STORE_HUNK 2000
26 static char *pNextFree = NULL;
27 static int bytesLeft = 0;
32 length = strlen( str ) + 1; /* what we need, including null */
34 if (length > bytesLeft)
36 /* no space. Allocate a new hunk. We lose the pointer to any
37 / old hunk. We don't care, as the names are never deleted.
39 pNextFree = (char*)new( STR_STORE_HUNK );
40 bytesLeft = STR_STORE_HUNK;
43 /* Copy the name and terminating null into the name store */
44 pStoredString = pNextFree;
45 memcpy( pStoredString, str, length );