Global buffers, are they more trouble than they're worth?

From: Peter Ajamian (
Date: 08/07/00

Something to ponder / comment on / etc...

CircleMUD defines several globals for use as temporary buffer space
(buf, buf1, buf2, etc...).  When coding my MUD, I find that for anything
other than an ACMD, I have to think twice about using one of these
buffers.  To use them might mean stepping on another function's toes.
To not use them or to declare them locally may mean wasting the memory
space to hold the locals.  I have often wondered why these globals were
even there to begin with, they tend to go against the good coding
practice of sticking to using locals for locals and globals for globals,
and the implications of using them could easily confuse a novice coder
(imagine the consequences of using buf in a recursive function).

Consequently I have fallen into the practice of declaring these
variables locally for every function they're used in except for ACMDs,
but I wonder if it would be worthwhile to remove them alltogether?  I
can understand the attempted savings in CPU time by not having to
allocate and deallocate space for them as locals everytime a function
declares them, but any decent optimizing compiler should completely wipe
out his concern.

So what other reasons are there to using them?  I know that they have
been set up in such a way so that the MUD will detect if they've been
overrun, but is that really worth all the extra overhead that they

Just something to ponder, comment about, reply to, etc.

Regards, Peter

     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     |  |

This archive was generated by hypermail 2b30 : 04/11/01 PDT