Click here to Skip to main content
15,895,084 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: pointers and array of pointers question Pin
David Crow8-Sep-06 8:04
David Crow8-Sep-06 8:04 
GeneralRe: pointers and array of pointers question Pin
kitty58-Sep-06 8:06
kitty58-Sep-06 8:06 
AnswerRe: pointers and array of pointers question Pin
Cedric Moonen8-Sep-06 8:18
Cedric Moonen8-Sep-06 8:18 
AnswerRe: pointers and array of pointers question Pin
Chris Losinger8-Sep-06 8:27
professionalChris Losinger8-Sep-06 8:27 
AnswerRe: pointers and array of pointers question Pin
David Crow8-Sep-06 8:28
David Crow8-Sep-06 8:28 
GeneralRe: pointers and array of pointers question Pin
kitty58-Sep-06 10:20
kitty58-Sep-06 10:20 
GeneralRe: pointers and array of pointers question Pin
David Crow8-Sep-06 10:26
David Crow8-Sep-06 10:26 
GeneralRe: pointers and array of pointers question Pin
Jörgen Sigvardsson8-Sep-06 11:33
Jörgen Sigvardsson8-Sep-06 11:33 
When you allocate a chunk of memory, what you get is a memory chunk at least as big as what you requested, and some extra data. The whole chunk looks like this:
[ Extra Data ][ Your data - X bytes ]
The pointer which new returns, is the adress of the first byte of [ Your data ]. The [ Extra Data ] chunk is used later on when you deallocate the memory. When you pass a pointer to delete for deallocation, delete will actually "step back" and take a peek at what's inside [ Extra Data ]. That chunk of data contains book keeping information about the memory allocation - which it really needs to be able to put the allocated memory back into the pool of unallocated memory.

If you increment the pointer value, it will no longer point to the beginning of the data chunk which new returned. So when you pass the modified pointer to delete, it will not find the book keeping information when it "steps back". It will find data from which you put into your data chunk, which delete will interpret as garbage...


--
Torn from tomorrow's headlines

Questionwindows system clock temper track Pin
dummy8088-Sep-06 7:19
dummy8088-Sep-06 7:19 
QuestionRe: windows system clock temper track Pin
David Crow8-Sep-06 8:02
David Crow8-Sep-06 8:02 
AnswerRe: windows system clock temper track Pin
Gary R. Wheeler9-Sep-06 5:38
Gary R. Wheeler9-Sep-06 5:38 
QuestionDecorated Splitter Bar - SOLVED Pin
#realJSOP8-Sep-06 6:51
mve#realJSOP8-Sep-06 6:51 
Questionvisual c++ 2005 newbie Pin
Lampros Giampouras8-Sep-06 6:48
Lampros Giampouras8-Sep-06 6:48 
AnswerRe: visual c++ 2005 newbie Pin
Jun Du8-Sep-06 7:11
Jun Du8-Sep-06 7:11 
GeneralRe: visual c++ 2005 newbie Pin
Lampros Giampouras8-Sep-06 7:28
Lampros Giampouras8-Sep-06 7:28 
AnswerRe: visual c++ 2005 newbie Pin
Cedric Moonen8-Sep-06 8:03
Cedric Moonen8-Sep-06 8:03 
QuestionRe: visual c++ 2005 newbie Pin
David Crow8-Sep-06 8:05
David Crow8-Sep-06 8:05 
AnswerRe: visual c++ 2005 newbie Pin
Cedric Moonen8-Sep-06 8:12
Cedric Moonen8-Sep-06 8:12 
GeneralRe: visual c++ 2005 newbie Pin
Jun Du8-Sep-06 9:13
Jun Du8-Sep-06 9:13 
QuestionApartment model, COM and misery (duplicate from the COM forum) Pin
BadJerry8-Sep-06 5:45
BadJerry8-Sep-06 5:45 
AnswerRe: Apartment model, COM and misery (duplicate from the COM forum) Pin
JWood8-Sep-06 6:53
JWood8-Sep-06 6:53 
GeneralRe: Apartment model, COM and misery (duplicate from the COM forum) Pin
BadJerry8-Sep-06 7:02
BadJerry8-Sep-06 7:02 
GeneralRe: Apartment model, COM and misery (duplicate from the COM forum) Pin
JWood8-Sep-06 7:39
JWood8-Sep-06 7:39 
GeneralRe: Apartment model, COM and misery (duplicate from the COM forum) Pin
BadJerry8-Sep-06 8:23
BadJerry8-Sep-06 8:23 
GeneralRe: Apartment model, COM and misery (duplicate from the COM forum) [modified] Pin
JWood8-Sep-06 8:44
JWood8-Sep-06 8:44 

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.