Click here to Skip to main content
15,890,882 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Generalfix formview Pin
sdfdsfa17-Jun-03 16:16
sdfdsfa17-Jun-03 16:16 
Generalwhat's the name of the control Pin
gucy17-Jun-03 15:10
gucy17-Jun-03 15:10 
QuestionHow to change size of a control dynamically Pin
chito17-Jun-03 15:04
chito17-Jun-03 15:04 
GeneralCRichEditCtrl and SetOptions Pin
Vancouver17-Jun-03 13:43
Vancouver17-Jun-03 13:43 
GeneralRe: CRichEditCtrl and SetOptions Pin
jfu28-Jan-13 17:56
jfu28-Jan-13 17:56 
GeneralRe: CRichEditCtrl and SetOptions Pin
jfu28-Jan-13 22:34
jfu28-Jan-13 22:34 
GeneralWindows Installer Pin
paulb17-Jun-03 13:19
paulb17-Jun-03 13:19 
GeneralYour thoughts on this singleton implementation Pin
Anonymous17-Jun-03 10:59
Anonymous17-Jun-03 10:59 
I have looked at the Modern C++ Design book and since none of the examples work in VC6 world, figured I should come up with something of my own.

So to start with, what do you think about this Singleton implementation?

header file


#include <windows.h>
class CSingleton
{

public:

static CSingleton & GetSingletonInstance ();

static void Guard();
static void UnGuard();

private:
CSingleton();
CSingleton(const CSingleton & );
virtual ~CSingleton();

static CSingleton * m_pSingleton;



static CRITICAL_SECTION m_CriticalSection;
static long m_lGuardCount;
};


cpp file

#include "Singleton.h"

CSingleton * CSingleton::m_pSingleton;
CRITICAL_SECTION CSingleton::m_CriticalSection;
long CSingleton::m_lGuardCount;

CSingleton::CSingleton()
{

}

CSingleton::~CSingleton()
{

}

CSingleton::CSingleton(const CSingleton & )
{

}

CSingleton & CSingleton::GetSingletonInstance()
{

if(!m_pSingleton)
{
Guard();
if(!m_pSingleton)
m_pSingleton = new CSingleton();
UnGuard();
}

return *m_pSingleton;
}

void CSingleton::Guard()
{
EnterCriticalSection(&m_CriticalSection);
m_lGuardCount++;
}

void CSingleton::UnGuard()
{
LeaveCriticalSection(&m_CriticalSection);
m_lGuardCount--;
}


How does this implementation look to you? The GuardCount is just there for reference. Doyou think Critical Section is enough or should I be using Events or Mutexes?
GeneralRe: Your thoughts on this singleton implementation Pin
AlexO18-Jun-03 3:31
AlexO18-Jun-03 3:31 
GeneralRe: Your thoughts on this singleton implementation Pin
Anonymous18-Jun-03 3:56
Anonymous18-Jun-03 3:56 
GeneralRe: Your thoughts on this singleton implementation Pin
AlexO18-Jun-03 4:13
AlexO18-Jun-03 4:13 
GeneralSetting a radio button as the default choice Pin
Jay Hova17-Jun-03 9:41
Jay Hova17-Jun-03 9:41 
GeneralRe: Setting a radio button as the default choice Pin
valikac17-Jun-03 10:02
valikac17-Jun-03 10:02 
GeneralRe: Setting a radio button as the default choice Pin
David Crow17-Jun-03 10:51
David Crow17-Jun-03 10:51 
GeneralRe: Setting a radio button as the default choice Pin
Ryan Binns17-Jun-03 16:18
Ryan Binns17-Jun-03 16:18 
GeneralRe: Setting a radio button as the default choice Pin
Jay Hova18-Jun-03 4:16
Jay Hova18-Jun-03 4:16 
QuestionHow do you create new object using &lt;vector&gt;? Pin
kleft17-Jun-03 9:06
kleft17-Jun-03 9:06 
AnswerRe: How do you create new object using ? Pin
AlexO17-Jun-03 9:14
AlexO17-Jun-03 9:14 
Generalusing SP_DRVINFO_DATA_V2 instead of SP_DRVINFO_DATA_V1 Pin
tessierjf17-Jun-03 8:28
tessierjf17-Jun-03 8:28 
Generalstoring data in Memory and accessing it for playback Pin
johnstonsk17-Jun-03 7:58
johnstonsk17-Jun-03 7:58 
GeneralRe: storing data in Memory and accessing it for playback Pin
AlexO17-Jun-03 8:39
AlexO17-Jun-03 8:39 
GeneralRe: storing data in Memory and accessing it for playback Pin
AlexO17-Jun-03 8:47
AlexO17-Jun-03 8:47 
GeneralRe: storing data in Memory and accessing it for playback Pin
johnstonsk17-Jun-03 8:47
johnstonsk17-Jun-03 8:47 
GeneralActiveX control stock property issue. Pin
Marion2817-Jun-03 7:30
Marion2817-Jun-03 7:30 
GeneralFunction to pass an CArray or Structure.. Pin
RobJones17-Jun-03 6:58
RobJones17-Jun-03 6:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.