C ++ free storage space: new

Source: Internet
Author: User

The new operator can create objects whose survival time does not depend on the scope, even after the function is returned. The new object is "free storage", or "heap object" or "created in dynamic storage ". Usage

Mynode * n = new mynode; // structure delete n; char * s = new char [length]; delete [] s; mynode * n = new mynode; // structure: delete n; char * s = new char [length]; delete [] s;

 

Generally, if the system does not provide memory management, use delete to release the memory after the heap object is used. Delete applies to a single object, and delete [] applies to arrays. The size of the heap object must be saved when it is created. Generally, one byte is required. When the new statement cannot allocate space, the bad_alloc exception is thrown. You can customize the set_new_handler (out_of_store) function before the new statement to process the exception.

Related Article

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.