[CODE] quick and dirty automatic string system

From: d. hall (dhall@APK.NET)
Date: 12/15/97


Last time I checked here, I heard of an automatic buffering system to
replace the global buffers built within the system.  I hacked up a brief
system which enables minimal fuss in regards to automatic strings.  The
prime concern is worrying about how to deal with malloc'ed strings, keeping
track of them, and to remember to return them all after you're done.  With
this system, just so long as you don't "free()" them, you can't really
"lose" them, nor worry about impending memory leaks.

I've devised a relatively simple system in which the strings are kept as a
pool, malloc'ed as necessary, and kept within a global stack.  Whenever a
string is requested from the global stack, they are placed upon a local
stack, which is also has it's own stack.  The cost in memory versus time
tradeoff is kept to a minimum by only malloc'ing the memory once, and
storing thereafter.

These files are part of a greater lib, which I haven't quite finished yet.
For those who want to clarify the missing functions, ifatal is simply a
printf bundled with an exit (-1).  imalloc, irealloc are alloc functions
that check for NULL's, a NULL causes a fatal error.

Please note the local stack is a set size in pointers to structures, which
is currently 16.  Hopefully you won't need more than 16 automatics strings
within on level of nesting, if so, just increase the #define.

sample.c is a brief example of usage, and tests the systems to 20 levels of
nesting.  debugging is currently set to on, #undef for intensive use.

d.


+------------------------------------------------------------+ | Ensure that you have read the CircleMUD Mailing List FAQ: | | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html | +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/08/00 PST