[gnutls-dev] living without global variables
bryanh at giraffe-data.com
Thu Dec 22 18:22:38 CET 2005
>These variables are constant during the lifetime of the application.
I didn't really mean to refer to those two root pointers as the global
variables -- the entire tree each points to is the global variable.
These trees are specifically designed (according to what I see in the
user's guide) to make separate sessions share stuff as it changes.
That's great for sessions that all belong to the same context, but
modules shouldn't be sharing with other modules inadvertently.
The most serious way that these "variables" change during the lifetime
of the application is when a piece (module) of the application does a
gnutls_global_deinit(). That would blow up some other module in the
same application that happens to be using gnutls.
In case it isn't clear what sort of "module" I'm talking about: I (and
plenty of others, I'm sure) want to distribute a programming library
that uses gnutls to provide some of its function. It should be
possible for my user to be blissfully ignorant of the gnutls stuff
going on inside the library, which means he doesn't worry about
initializing and deinitializing the gnutls library. His program may use
gnutls for its own purposes, and may use some other library that uses
gnutls under the covers like mine.
It's common in modern libraries to avoid process-global variables
completely as a matter of good programming style (it helps not only
with modularity but thread safety and recursion as well).
Bryan Henderson Phone 408-621-2000
San Jose, California
More information about the Gnutls-devel