What is the difference between new/delete and malloc/free?
Related (duplicate?): In what cases do I use malloc vs new?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
new/deletenew(standard version) never returns aNULL(will throw on failure).malloc/freeis implementation defined.std::set_new_handler).operator new/operator deletecan be overridden legally.malloc/freevoid*.NULLon failure.new/delete.malloc/freecan NOT be overridden legally.Table comparison of the features:
new/deletemalloc/freevoid*NULL)NULLTechnically, memory allocated by
newcomes from the ‘Free Store’ while memory allocated bymalloccomes from the ‘Heap’. Whether these two areas are the same is an implementation detail, which is another reason thatmallocandnewcannot be mixed.