Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > new or malloc()

Reply
Thread Tools

new or malloc()

 
 
DigitalDragon
Guest
Posts: n/a
 
      08-08-2003
which is better? "new" or the good old "malloc()". what is (if there is) the
diference?


--
--------------------------------
Krešimir Špes
B.B. & Idol Graphics
http:// bb.gamer.hr


 
Reply With Quote
 
 
 
 
Jakob Bieling
Guest
Posts: n/a
 
      08-08-2003
"DigitalDragon" <(E-Mail Removed)> wrote in message
news:bh07db$9cg$(E-Mail Removed)...
> which is better? "new" or the good old "malloc()". what is (if there is)

the
> diference?



Use new and new[]. Difference is, new is type safe and calls
constructors for classes/structs, malloc is/does none of that.

hth
--
jb

(replace y with x if you want to reply by e-mail)


 
Reply With Quote
 
 
 
 
Karl Heinz Buchegger
Guest
Posts: n/a
 
      08-08-2003


DigitalDragon wrote:
>
> which is better? "new" or the good old "malloc()". what is (if there is) the
> diference?


malloc allocates storage
new allocates storage and constructs an object in that storage

So the question: 'which one is better?' makes no sense - they
do different things.

--
Karl Heinz Buchegger
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
Alexander Terekhov
Guest
Posts: n/a
 
      08-08-2003

Karl Heinz Buchegger wrote:
>
> DigitalDragon wrote:
> >
> > which is better? "new" or the good old "malloc()". what is (if there is) the
> > diference?

>
> malloc allocates storage


and doesn't throw an exception. As for "new", it's all in the
declarations (placement and array functions aside for a moment):

void * operator new(std::size_t size) throw(std::bad_alloc);
void * operator new(std::size_t size, const std::nothrow_t &) throw();

> new allocates storage and constructs an object in that storage


Nah, new-expression is hardly related to malloc().

regards,
alexander.
 
Reply With Quote
 
 
 
Reply

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 On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Javascript new-new-new-new-newbee weblinkunlimited@gmail.com Javascript 2 03-11-2008 01:15 AM
New computer, New OS, New Wireless Problem :-\ =?Utf-8?B?RGFu?= Wireless Networking 3 07-31-2005 02:11 PM
[Firefox] Use New Tab instead of New Window? paul j Firefox 7 04-07-2005 09:40 PM
Why can not register a new .net passport or a new hotmail account Alick Lv MCSD 1 01-04-2004 06:12 PM



Advertisments