Click here to Skip to main content
15,887,477 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Right way to delete a pointer [modified] Pin
Nish Nishant2-Jun-06 3:54
sitebuilderNish Nishant2-Jun-06 3:54 
GeneralRe: Right way to delete a pointer [modified] Pin
Zac Howland2-Jun-06 4:58
Zac Howland2-Jun-06 4:58 
GeneralRe: Right way to delete a pointer [modified] Pin
Nemanja Trifunovic2-Jun-06 6:17
Nemanja Trifunovic2-Jun-06 6:17 
GeneralRe: Right way to delete a pointer [modified] Pin
Zac Howland2-Jun-06 8:09
Zac Howland2-Jun-06 8:09 
GeneralRe: Right way to delete a pointer Pin
Nemanja Trifunovic2-Jun-06 12:50
Nemanja Trifunovic2-Jun-06 12:50 
GeneralRe: Right way to delete a pointer [modified] Pin
Nemanja Trifunovic2-Jun-06 4:48
Nemanja Trifunovic2-Jun-06 4:48 
AnswerRe: Right way to delete a pointer Pin
SteveKing2-Jun-06 3:40
SteveKing2-Jun-06 3:40 
AnswerRe: Right way to delete a pointer Pin
James R. Twine2-Jun-06 4:39
James R. Twine2-Jun-06 4:39 
   Another reason for doing that is that the address used for the recently-deallocated memory may still be valid in your address space and while not technically valid for use, accessing it might not cause an IPF or Access Violation.  For example:
TCHAR *pcBuffer = new TCHAR[ 1024 ];
 
delete [] pcBuffer;
pcBuffer[ 1 ] = _T( 'A' );
   The above code may not crash even though the pointer is technically invalid.

  By setting it to NULL, you just about guarantee that accessing it will cause an Access Violation (at least if on Win32 and if the access range of the pointer is < 4096, because that hits the reserved "NULL pointer page" which causes an instant exception, IIRC).

   Peace!

-=- James
If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
DeleteFXPFiles & CheckFavorites
(Please rate this post!)
QuestionCurrent directory Pin
racing572-Jun-06 1:30
racing572-Jun-06 1:30 
AnswerRe: Current directory Pin
Hamid_RT2-Jun-06 1:32
Hamid_RT2-Jun-06 1:32 
GeneralRe: Current directory Pin
racing572-Jun-06 1:49
racing572-Jun-06 1:49 
GeneralRe: Current directory Pin
Nibu babu thomas2-Jun-06 3:06
Nibu babu thomas2-Jun-06 3:06 
GeneralRe: Current directory Pin
David Crow2-Jun-06 3:17
David Crow2-Jun-06 3:17 
QuestionPackage Pin
VinayCool2-Jun-06 1:22
VinayCool2-Jun-06 1:22 
AnswerRe: Package Pin
Hamid_RT2-Jun-06 1:40
Hamid_RT2-Jun-06 1:40 
AnswerRe: Package Pin
SteveKing2-Jun-06 3:49
SteveKing2-Jun-06 3:49 
QuestionTimers in VC++ Pin
Sharath862-Jun-06 1:08
Sharath862-Jun-06 1:08 
AnswerRe: Timers in VC++ Pin
Amar Sutar2-Jun-06 1:17
Amar Sutar2-Jun-06 1:17 
AnswerRe: Timers in VC++ [modified] Pin
_AnsHUMAN_ 2-Jun-06 1:21
_AnsHUMAN_ 2-Jun-06 1:21 
AnswerRe: Timers in VC++ [modified] Pin
James R. Twine2-Jun-06 4:50
James R. Twine2-Jun-06 4:50 
AnswerRe: Timers in VC++ Pin
Hamid_RT2-Jun-06 1:22
Hamid_RT2-Jun-06 1:22 
QuestionInvoke Default Mail Client (with attachment) [modified] Pin
QuickDeveloper2-Jun-06 1:06
QuickDeveloper2-Jun-06 1:06 
AnswerRe: Invoke Default Mail Client (with attachment) [modified] Pin
Brad Bruce2-Jun-06 2:10
Brad Bruce2-Jun-06 2:10 
AnswerRe: Invoke Default Mail Client (with attachment) [modified] Pin
David Crow2-Jun-06 3:21
David Crow2-Jun-06 3:21 
AnswerRe: Invoke Default Mail Client (with attachment) Pin
Michael Dunn2-Jun-06 7:47
sitebuilderMichael Dunn2-Jun-06 7:47 

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.