Re: [long] Poll: global buffers

From: George Greer (
Date: 07/21/01

On Sat, 21 Jul 2001, Mike Breuer wrote:

>----- Original Message -----
>From: "George Greer" <greerga@CIRCLEMUD.ORG>
>> This was Novell NetWare client library code so it was much more convoluted
>> than that and wouldn't work in a single if().  In particular, I couldn't
>> just bend the API to my whim and make the cleanup functions return the
>> appropriate values.
>int my_cleanup(void *var) { cleanup(var); return 0; }

You'd need 'return 1;' I believe, but that doesn't change the yuckiness. :)

>> Your if() works when the planets and API are aligned on proper return
>> values.
>Or with a little forethought.  My point is not to pick apart your example,
>but to show that there are always a variety of ways to handle a particular
>problem.  One argument I've seen for goto's is their ability to break out of
>nested loops:
>void func() {
>  int i, j;
>  for (i = 0; i < 1024; i++) {
>    for (j = 0; j < i; j++) {
>       /* .... Do something useful */
>       if (/* condition */) goto bailout;
>    }
>  }
>  bailout:
>  /* Perform some sort of cleanup */

Right. Much nicer than testing for the inner condition at the bottom of the
outer for() loop just to do another break;

>But this same thing can be accomplished by putting the loops in a function
>and using a return to bail out instead of a goto.

Which is the bigger abuse of the language: making a function simply due to
language deficiencies or using goto? You decide. (It would also depend on
if that loop is needed elsewhere or is a one-time thing.)

>> Tangents...
>Just to get us back on track, let me expand on my earlier response about
>globals.  Most respondants seem to think that globals provide increased
>performance, although there is actually a performance trade-off associated
>with them.  While saving allocation time, you are permanently increasing the
>memory footprint of the application.  This can lead to performance
>degredation as well.

I have less of a problem with memory of a gloal variable used constantly
than memory of a static variable used every now and then.  But we don't
have much of a choice on some functions like ctime().

>I admit some of my opinion is based on an O-O bias that disagrees with
>globals on principal.  :)

Embrace the inner evil. :)

George Greer

   | FAQ: |
   | Archives: |

This archive was generated by hypermail 2b30 : 12/06/01 PST