Difference in implementation

Posted on 2003-02-25
Medium Priority
Last Modified: 2010-05-18
What is the difference between malloc() and the new operator?
Question by:trinitrotoluene
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

eranborovik earned 80 total points
ID: 8016460
In most cases new actually calls malloc. The real difference is that new can be overloaded, so the user can
change the way it behaves. For example, maintain a private
pool of memory from which new will take memory.

another thing, new doesn't exist in C but only in C++.
You can safely use malloc also in c++, but you must make sure you call "free" to free the memory. When working with new, you must call "delete" to free the memory.

The most importan thing to notice, is that new also calls
the appropriate object constructor while malloc doesn't.

Expert Comment

ID: 9447522
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Post your closing recommendations!  No comment means you don't care.

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Simple Linear Regression
Six Sigma Control Plans
Suggested Courses
Course of the Month8 days, 12 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question