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.