By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,918 Members | 2,258 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,918 IT Pros & Developers. It's quick & easy.

Malloc() and new()

P: n/a
we knows that we can use free() for Malloc and delete() for new.
can we use delete for new and free for malloc?

thankx in advance.

Dec 26 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
hi meendar,
have a look at this. your question is better answered here

http://www.parashift.com/c++-faq-lit....html#faq-16.3

Suriya

Dec 26 '05 #2

P: n/a
On 25 Dec 2005 22:19:09 -0800 in comp.lang.c++, "meendar"
<as****************@gmail.com> wrote,
we knows that we can use free() for Malloc and delete() for new.
can we use delete for new and free for malloc?


No.

(However, there is no requirement that the implementation trap the
mismatch, so you may appear to get away with it for a while. Be
advised that it is only waiting for the most embarrassing moment to
bite you.)

Dec 26 '05 #3

P: n/a
sorry the question is.

we knows that we can use free() for Malloc and delete() for new.
can we use free() for new and delete() for malloc?

Dec 26 '05 #4

P: n/a
meendar wrote:
sorry the question is.

we knows that we can use free() for Malloc and delete() for new.
can we use free() for new and delete() for malloc?


Hi Meendar

Did you make an effort to go through the link that was given by Suriya
? That answers your question. Please go through that link.

Thanks!! and have a nice day!!
Jaspreet

Dec 26 '05 #5

P: n/a
"suriya" <ak*********@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
hi meendar,
have a look at this. your question is better answered here

http://www.parashift.com/c++-faq-lit....html#faq-16.3

Suriya


That link does not state the reason you should not use free for new.

new'ed memory may be allocated in some method other than malloc by the
compiler. Also, new could be overridden (?) to gain memory in some other
method also.
Dec 26 '05 #6

P: n/a
Jim Langston wrote:
"suriya" <ak*********@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
hi meendar,
have a look at this. your question is better answered here

http://www.parashift.com/c++-faq-lit....html#faq-16.3

Suriya


That link does not state the reason you should not use free for new.

new'ed memory may be allocated in some method other than malloc by the
compiler. Also, new could be overridden (?) to gain memory in some other
method also.

There is nothing that says new'd memory even without the override is
allocated in the same way as malloc.
Dec 26 '05 #7

P: n/a

"Ron Natalie" <ro*@spamcop.net> wrote in message
news:43***********************@news.newshosting.co m...
Jim Langston wrote:
"suriya" <ak*********@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
hi meendar,
have a look at this. your question is better answered here

http://www.parashift.com/c++-faq-lit....html#faq-16.3

Suriya


That link does not state the reason you should not use free for new.

new'ed memory may be allocated in some method other than malloc by the
compiler. Also, new could be overridden (?) to gain memory in some other
method also.

There is nothing that says new'd memory even without the override is
allocated in the same way as malloc.


Well, yeah, that's what I said.
Dec 27 '05 #8

P: n/a
Hi meendar,
We can use fee for malloc, and delete for new. because at the time of
using new operator its can be done 2 steps. allocation of memory(like
malloc) and it calls constructor.If by using free function ,it doesn't
calls destructor.So we didn't use free function for new operator.

Dec 27 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.