Click here to Skip to main content
15,911,789 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionHow to delete *ptr correctly? Pin
uus9929-Jun-04 4:03
uus9929-Jun-04 4:03 
AnswerRe: How to delete *ptr correctly? Pin
David Crow29-Jun-04 4:24
David Crow29-Jun-04 4:24 
GeneralRe: How to delete *ptr correctly? Pin
uus9929-Jun-04 4:26
uus9929-Jun-04 4:26 
AnswerRe: How to delete *ptr correctly? Pin
Antony M Kancidrowski29-Jun-04 4:33
Antony M Kancidrowski29-Jun-04 4:33 
GeneralRe: How to delete *ptr correctly? Pin
uus9929-Jun-04 4:48
uus9929-Jun-04 4:48 
GeneralRe: How to delete *ptr correctly? Pin
Jeremy Falcon29-Jun-04 6:37
professionalJeremy Falcon29-Jun-04 6:37 
GeneralRe: How to delete *ptr correctly? Pin
Henry miller29-Jun-04 7:17
Henry miller29-Jun-04 7:17 
GeneralRe: How to delete *ptr correctly? Pin
digwizfox29-Jun-04 9:48
digwizfox29-Jun-04 9:48 
That's interesting. I would think that the proper usage of delete contributed to the solution as well. Both are absolutely critical to ensuring that your code works properly. Not using new and delete properly will cause undefined behavior (sometimes your code will crash, sometimes it won't).

I've seen code like this:

#include "gconst.h"

struct globalmem
{
int counter;
int[SIZE] nDataBuffer;
//just as an example, the real data struct had many
//other attributes as well
}

//now later, in some other piece of code

globalmem* gpGlobalMem = new globalmem;

//Now even later upon application exiting

delete[] globalmem; //oops! use delete globalmem
//remember, if new was used, delete should be used for
//destruction. Always use the same format of new and
//delete (even though there is an array in global mem
//you still instantiated only 1 globalmem structure
//using new.


Now what was really weird was that the delete[] globalmem statement was in our code for years, even though it was wrong and never caused problems. But after adding even more variables to the data structure during the enhancement to a system, the software just started crashing when trying to exit the application.
GeneralChange radio button group VC++ 6.0 Pin
WerFoog29-Jun-04 3:54
WerFoog29-Jun-04 3:54 
GeneralRe: Change radio button group VC++ 6.0 Pin
rrrado29-Jun-04 4:14
rrrado29-Jun-04 4:14 
GeneralRe: Change radio button group VC++ 6.0 Pin
Blake Miller29-Jun-04 4:15
Blake Miller29-Jun-04 4:15 
GeneralRe: Change radio button group VC++ 6.0 Pin
#realJSOP29-Jun-04 9:17
professional#realJSOP29-Jun-04 9:17 
QuestionAnother way to kill process other than terminate?? Pin
Anonymous29-Jun-04 2:09
Anonymous29-Jun-04 2:09 
AnswerRe: Another way to kill process other than terminate?? Pin
rrrado29-Jun-04 3:49
rrrado29-Jun-04 3:49 
AnswerRe: Another way to kill process other than terminate?? Pin
palbano29-Jun-04 4:29
palbano29-Jun-04 4:29 
QuestionHow to send a signal to another process??? Pin
Anonymous29-Jun-04 2:01
Anonymous29-Jun-04 2:01 
AnswerRe: How to send a signal to another process??? Pin
RadioShark29-Jun-04 2:10
RadioShark29-Jun-04 2:10 
GeneralRe: How to send a signal to another process??? Pin
A T I F29-Jun-04 2:49
A T I F29-Jun-04 2:49 
AnswerRe: How to send a signal to another process??? Pin
#realJSOP29-Jun-04 2:31
professional#realJSOP29-Jun-04 2:31 
Questionhow to read a text from a file??????Help!!!!!!!!! Pin
rogerlew29-Jun-04 0:41
rogerlew29-Jun-04 0:41 
AnswerRe: how to read a text from a file??????Help!!!!!!!!! Pin
Antony M Kancidrowski29-Jun-04 1:02
Antony M Kancidrowski29-Jun-04 1:02 
AnswerRe: how to read a text from a file??????Help!!!!!!!!! Pin
Manfred Staiger29-Jun-04 1:12
Manfred Staiger29-Jun-04 1:12 
AnswerRe: how to read a text from a file??????Help!!!!!!!!! Pin
#realJSOP29-Jun-04 2:32
professional#realJSOP29-Jun-04 2:32 
GeneralRe: how to read a text from a file??????Help!!!!!!!!! Pin
Antony M Kancidrowski29-Jun-04 4:22
Antony M Kancidrowski29-Jun-04 4:22 
QuestionHow do you know if it's a file or directory Pin
no_reg_name29-Jun-04 0:28
no_reg_name29-Jun-04 0:28 

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.