I'm trying to use a singleton in a DLL to globally configure logging. While everything works fine with one EXE using the DLL, when another EXE uses the same DLL at the same time, they seem to share the singleton (i.e. memory location and value of singleton and m_verbose
are identical in both processes).
Shouldn't the DLL data memory be separate for the different processes? How could I get the singleton not to share the variable m_verbose
in particular?
I'm on Windows using MSVC. This is my singleton code in the header:
#if COMPILING_DLL
#define DLLEXPORT __declspec(dllexport)
#else
#define DLLEXPORT __declspec(dllimport)
#endif
struct LogVerbose
{
static LogVerbose& instance()
{
static LogVerbose logVerbose;
return logVerbose;
}
LogVerbose(const LogVerbose&) = delete;
LogVerbose& operator = (const LogVerbose&) = delete;
static COMPILING_DLL bool isVerbose();
static COMPILING_DLL void setVerbose(bool verbose = true);
private:
LogVerbose() : m_verbose(false) {}
~LogVerbose() {}
bool m_verbose;
};
isVerbose
and setVerbose
are defined in the .cpp file but are mere accessors.
Thanks for any help.