Compare Malloc/free and New/delete

Source: Internet
Author: User
Compare Malloc/free and New/delete

?? When it comes to memory allocation, it is common to use malloc with Free.malloc and free as the standard library function for C++/C, New/delete is the C + + operator. They can all be used to request dynamic memory and free memory.

?? For objects of non-intrinsic data types, light Malloc/free cannot meet the requirements of dynamic objects. Objects are automatically executed when they are created, and the object executes the destructor automatically before it dies. Because Malloc/free is a library function and not an operator, the task of executing constructors and destructors cannot be imposed on malloc/free, not within the control of the compiler.

?? Therefore, C + + requires an operator new that can perform dynamic memory allocation and initialization, and an operator delete that can perform cleanup and freeing of memory work.

Copyright NOTICE: This article for csdn bo Master [Applebite] (Http://blog.csdn.net/applebite) original articles, reproduced please indicate the source, infringement must be studied.

Compare Malloc/free and New/delete

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.