Click here to Skip to main content
15,892,059 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: C++ String Creation Pin
Aescleal23-May-10 9:36
Aescleal23-May-10 9:36 
QuestionIntel Compiler IA-32 11.0.061 installation on VS 2010 question Pin
Chesnokov Yuriy23-May-10 4:07
professionalChesnokov Yuriy23-May-10 4:07 
QuestionOLE interface for Crichedit Pin
ForNow22-May-10 19:27
ForNow22-May-10 19:27 
Questionnew vs free and malloc vs delete Pin
msr_codeproject22-May-10 18:24
msr_codeproject22-May-10 18:24 
AnswerRe: new vs free and malloc vs delete Pin
loyal ginger22-May-10 19:01
loyal ginger22-May-10 19:01 
AnswerRe: new vs free and malloc vs delete Pin
Stephen Hewitt22-May-10 22:11
Stephen Hewitt22-May-10 22:11 
AnswerRe: new vs free and malloc vs delete Pin
Aescleal23-May-10 5:39
Aescleal23-May-10 5:39 
AnswerRe: new vs free and malloc vs delete Pin
John R. Shaw23-May-10 6:23
John R. Shaw23-May-10 6:23 
These methods are to be used in pairs and you should not mix them.

If you allocate memory with malloc then you need to free it with free. The same goes for new and delete.

C Memory Functions
malloc: Allocates an uninitialized block of memory, given the number of bytes.
calloc: Allocates a zero initialized block of memory, given the number of elements and the size of the element.
free: Deletes the memory allocated by malloc or calloc.

C++Memory Operators
new: Is an operator that allocates storage for one or more elements (objects) and then calls the constructor of each element to initialize it.
delete: Is an operator that calls the destructor for each of the stored elements and then frees the associated storage.

As you can see from the above, new is not equivalent to malloc and delete is not equivalent to free. They are not enterchangable and should not be mixed. When writing C++ code you should use new and delete, unless you have a very good reason not to.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence." - Edsger Dijkstra
"I have never been lost, but I will admit to being confused for several weeks. " - Daniel Boone

AnswerRe: new vs free and malloc vs delete Pin
MS_TJ23-May-10 19:52
MS_TJ23-May-10 19:52 
GeneralRe: new vs free and malloc vs delete Pin
Aescleal24-May-10 4:25
Aescleal24-May-10 4:25 
Questionopen txt file form web or ftp ? Pin
da_22-May-10 3:38
da_22-May-10 3:38 
AnswerRe: open txt file form web or ftp ? Pin
Richard MacCutchan22-May-10 4:28
mveRichard MacCutchan22-May-10 4:28 
AnswerRe: open txt file form web or ftp ? Pin
norish22-May-10 8:58
norish22-May-10 8:58 
AnswerRe: open txt file form web or ftp ? Pin
David Crow22-May-10 16:28
David Crow22-May-10 16:28 
GeneralRe: open txt file form web or ftp ? Pin
wangningyu23-May-10 5:43
wangningyu23-May-10 5:43 
AnswerRe: open txt file form web or ftp ? Pin
Hristo-Bojilov23-May-10 3:44
Hristo-Bojilov23-May-10 3:44 
GeneralRe: open txt file form web or ftp ? Pin
da_23-May-10 4:09
da_23-May-10 4:09 
GeneralRe: open txt file form web or ftp ? Pin
Hristo-Bojilov23-May-10 4:59
Hristo-Bojilov23-May-10 4:59 
QuestionRelease IGraphBuilder interface in directshow problem Pin
raj157622-May-10 0:25
raj157622-May-10 0:25 
AnswerRe: Release IGraphBuilder interface in directshow problem Pin
norish22-May-10 9:09
norish22-May-10 9:09 
QuestionChange Event of excel Pin
trioum21-May-10 23:55
trioum21-May-10 23:55 
GeneralRe: Change Event of excel Pin
norish22-May-10 9:14
norish22-May-10 9:14 
QuestionGDI+ JPEG to binary Pin
hxhl9521-May-10 17:30
hxhl9521-May-10 17:30 
AnswerRe: GDI+ JPEG to binary Pin
hxhl9521-May-10 18:27
hxhl9521-May-10 18:27 
GeneralRe: GDI+ JPEG to binary Pin
Alain Rist21-May-10 20:21
Alain Rist21-May-10 20:21 

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.