What we call memory is inherently understandable as a resource, managed by the operating system, and what we can do is apply and release .
Application and release is memory management.
How to apply and release memory?
Here are two operators:
New application
Delete Release
Request a Memory:
Defines a pointer to accept the memory requested by the new operator with a pointer
Nxp
request a piece of memory :
int *arr=new int[10];//Request block memory
delete []arr; free block memory
Memory Operation considerations:
1. Memory Management Method:
2. Request memory to determine success and free memory:
int *p =new int[100];
if (p==null) {
Memory allocation failure
}
delete [] p;
P=null;
int *p=new int;
if (p==null) {
Memory allocation failure
}
Delete p;
P=null; Why should I finally assign a null pointer to P?
If pail is empty, the pointer also points to memory, and if we delete again, the same piece of memory is reclaimed two times, an exception occurs.
Memory management for C + +