Click here to Skip to main content
15,900,258 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: CString problem Pin
Try25-Feb-07 20:20
Try25-Feb-07 20:20 
GeneralRe: CString problem Pin
david bagaturia25-Feb-07 21:04
david bagaturia25-Feb-07 21:04 
QuestionHow to create a new document template that does not have Frame/View Pin
Nataraj197825-Feb-07 19:56
Nataraj197825-Feb-07 19:56 
QuestionHow to show my program in context menu Pin
Max++25-Feb-07 19:55
Max++25-Feb-07 19:55 
AnswerRe: How to show my program in context menu Pin
Michael Dunn25-Feb-07 20:34
sitebuilderMichael Dunn25-Feb-07 20:34 
GeneralRe: How to show my program in context menu Pin
prasad_som25-Feb-07 20:37
prasad_som25-Feb-07 20:37 
AnswerRe: How to show my program in context menu Pin
prasad_som25-Feb-07 20:35
prasad_som25-Feb-07 20:35 
QuestionPreventing dangling pointers Pin
Waldermort25-Feb-07 19:53
Waldermort25-Feb-07 19:53 
I have staring at my code for an hour now thinking of a suitable way to overcome this problem.

I have a class ( classA ) which has a static std::list of struct ( containg a classB pointer ) pointers as a member. The purpose of classA is to map any derived classes to an instance of classB depending on certain paramaters. Within the struct is a reference count of all the derived classes which are using an instance of classB.

class classA
{
    typedef struct tagBATCHMAP
    {
        DWORD        VertexType;
        DWORD_PTR    Texture;
        classB*      Batch;
        UINT         RefCount;
    } BATCHMAP, *LPBATCHMAP;
 
public:
    static void    DeleteAll         ( void );
    static void    CollectGarbage    ( void );
 
protected:
    classA                           ( void );
    virtual ~classA                  ( void );
 
    bool           AddBatch          ( DWORD dwType, DWORD_PTR dwpTexture );
    UINT           Release           ( void );
 
private:
    bool           CreateInstance    ( DWORD dwType, DWORD_PTR dwpTexture );
 
private:
    static std::list< LPBATCHMAP >   s_InstanceMap;
 
    LPBATCHMAP                       m_BatchMap;
};

Since the BATCHMAP and ClassB are created dynamically, the CollectGarbage() method will delete any 0 referenced instaces at an appropriate time ( creating and deleteing are time consuming ). Everything works good and well until the DeleteAll() method is called ( which erases everything regardless of reference counts ) which is usually on program termination but may be called at any other time.

As you can see, classA holds a pointer to it's instance of classB ( again for timing reasons ). Once DeleteAll() is called this member pointer will be dangling. I can't think of a suitable way to overcome this.
AnswerRe: Preventing dangling pointers Pin
Cedric Moonen25-Feb-07 20:31
Cedric Moonen25-Feb-07 20:31 
GeneralRe: Preventing dangling pointers Pin
Waldermort25-Feb-07 20:39
Waldermort25-Feb-07 20:39 
GeneralRe: Preventing dangling pointers Pin
ThatsAlok26-Feb-07 18:15
ThatsAlok26-Feb-07 18:15 
Questionallocator for a class derived from CDBVariant Pin
prithaa25-Feb-07 19:17
prithaa25-Feb-07 19:17 
QuestionRe: allocator for a class derived from CDBVariant Pin
prasad_som25-Feb-07 20:42
prasad_som25-Feb-07 20:42 
AnswerRe: allocator for a class derived from CDBVariant Pin
prithaa25-Feb-07 21:05
prithaa25-Feb-07 21:05 
GeneralRe: allocator for a class derived from CDBVariant Pin
Cedric Moonen25-Feb-07 21:31
Cedric Moonen25-Feb-07 21:31 
Questionlinking data structure to ODBC Pin
Susanta57825-Feb-07 18:59
Susanta57825-Feb-07 18:59 
AnswerRe: linking data structure to ODBC Pin
Try25-Feb-07 20:07
Try25-Feb-07 20:07 
GeneralRe: linking data structure to ODBC Pin
Susanta57828-Feb-07 0:41
Susanta57828-Feb-07 0:41 
QuestionProblems with clearing a combobox using ResetContent..? Pin
Vinod Sankaranarayanan25-Feb-07 18:58
Vinod Sankaranarayanan25-Feb-07 18:58 
AnswerRe: Problems with clearing a combobox using ResetContent..? Pin
ThatsAlok25-Feb-07 19:48
ThatsAlok25-Feb-07 19:48 
QuestionWhy? Pin
Rajesh R Subramanian25-Feb-07 20:35
professionalRajesh R Subramanian25-Feb-07 20:35 
AnswerRe: Why? Pin
Mark Salsbery26-Feb-07 7:53
Mark Salsbery26-Feb-07 7:53 
NewsPlease! Pin
Rajesh R Subramanian26-Feb-07 17:32
professionalRajesh R Subramanian26-Feb-07 17:32 
GeneralRe: Please! Pin
Mark Salsbery27-Feb-07 7:46
Mark Salsbery27-Feb-07 7:46 
GeneralRe: Please! Pin
Rajesh R Subramanian27-Feb-07 8:13
professionalRajesh R Subramanian27-Feb-07 8:13 

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.