Global variables are not bad when used properly.
Just don't abuse them. Some people use global variables to get information into a function and results out of a function, instead of simply passing a pointer to the function and allowing the function to modify the pointer's information as necessary.
I once wrote an application that utilized shared memory segments to store the information it read.
Then I wrote an interface into that shared memory, which is usually faster than accessing the disk.
In my case, I ran stored procedures, and stored the data into memory for later use, but it only ran the stored procedures upon initial load for speed purposes.
This can be done in both Windows and Unix (or flavors of it).
The best approach, is to provide a class which you interface with the INI file, registry, or shared memory. The reason for this, is that you can obviously change wherever it is stored, without affecting the operation of the program itself.
Kind of like the class below. Keep in mind that the implementation file for things like the "getIntAppSettings()", can simply look like this so that the reading/writing is all done in one or two methods.
int applicationINI::getIntAppSettings(char *appName, char *settingName)
{
return (atoi(getAppSettings(appName, settingName));
}
Here's the sample class:
class applicationINI
{
public:
applicationINI();
~applicationINI();
// Method to get an application specific setting
char *getAppSetting(char *appName, char *settingName);
int getIntAppSetting(char *appName, char *settingName);
long getLongAppSetting(char *appName, char *settingName);
double getDoubleAppSetting(char *appName, char *settingName);
// Methods to set an application specific setting
bool setAppSetting(char *appName, char *settingName, char *value);
bool setAppSetting(char *appName, char *settingName, int value);
bool setAppSetting(char *appName, char *settingName, long value);
bool setAppSetting(char *appName, char *settingName, double value);
private:
int app
}
That way, your application doesn't care what device it is stored on, only the "applicationINI" class does, and handles all of that for you.
Oh, and the way that this was run, is that the item that stored the data in shared memory was a self-contained system tray application that provided that data.