Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old December 26th, 2005, 06:25 AM
meendar
Guest
 
Posts: n/a
Default Malloc() and new()

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.

  #2  
Old December 26th, 2005, 06:35 AM
suriya
Guest
 
Posts: n/a
Default Re: Malloc() and new()

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

  #3  
Old December 26th, 2005, 06:35 AM
David Harmon
Guest
 
Posts: n/a
Default Re: Malloc() and new()

On 25 Dec 2005 22:19:09 -0800 in comp.lang.c++, "meendar"
<askjavaprogrammers@gmail.com> wrote,[color=blue]
>we knows that we can use free() for Malloc and delete() for new.
>can we use delete for new and free for malloc?[/color]

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.)

  #4  
Old December 26th, 2005, 06:45 AM
meendar
Guest
 
Posts: n/a
Default Re: Malloc() and new()

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?

  #5  
Old December 26th, 2005, 08:25 AM
Jaspreet
Guest
 
Posts: n/a
Default Re: Malloc() and new()

meendar wrote:[color=blue]
> 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?[/color]

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

  #6  
Old December 26th, 2005, 08:55 AM
Jim Langston
Guest
 
Posts: n/a
Default Re: Malloc() and new()

"suriya" <aktersuriya@gmail.com> wrote in message
news:1135578339.232497.316870@o13g2000cwo.googlegr oups.com...[color=blue]
> 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
>[/color]

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.


  #7  
Old December 26th, 2005, 05:15 PM
Ron Natalie
Guest
 
Posts: n/a
Default Re: Malloc() and new()

Jim Langston wrote:[color=blue]
> "suriya" <aktersuriya@gmail.com> wrote in message
> news:1135578339.232497.316870@o13g2000cwo.googlegr oups.com...[color=green]
>> 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
>>[/color]
>
> 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.
>
>[/color]
There is nothing that says new'd memory even without the override is
allocated in the same way as malloc.
  #8  
Old December 27th, 2005, 12:55 AM
Jim Langston
Guest
 
Posts: n/a
Default Re: Malloc() and new()


"Ron Natalie" <ron@spamcop.net> wrote in message
news:43b020eb$0$11599$9a6e19ea@news.newshosting.co m...[color=blue]
> Jim Langston wrote:[color=green]
>> "suriya" <aktersuriya@gmail.com> wrote in message
>> news:1135578339.232497.316870@o13g2000cwo.googlegr oups.com...[color=darkred]
>>> 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
>>>[/color]
>>
>> 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.[/color]
> There is nothing that says new'd memory even without the override is
> allocated in the same way as malloc.[/color]

Well, yeah, that's what I said.


  #9  
Old December 27th, 2005, 03:55 AM
skishorev@yahoo.co.in
Guest
 
Posts: n/a
Default Re: Malloc() and new()

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.

 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles