Collection
zero Useful+1
zero

Static memory

Computer terminology
Static memory uses stack space memory and does not need to be allocated by programmers themselves. because Static variable Occupied storage space about compiler It can be predicted that static memory only needs to be declared directly when programming. On the contrary Dynamic memory Is required by programmer Allocate and reclaim memory as needed. Dynamic memory is used to execute applications that occupy memory due to external requests memory allocation Sometimes the new keyword or malloc or calloc function will be used. The reason why programmers need to allocate memory themselves is that sometimes they cannot determine how much memory the program needs.
Chinese name
Static memory
Foreign name
Static memory
Features
static state storage space about compiler Is expected
Field
computer

significance

Announce
edit
Static memory uses stack space memory, not programmer Allocate by yourself. because Static variable Occupied storage space about compiler It can be predicted that static memory only needs to be declared directly when programming. On the contrary Dynamic memory Is required by programmer Allocate and reclaim memory as needed. Dynamic memory is used to execute applications that occupy memory due to external requests memory allocation Sometimes the new keyword or malloc or calloc function will be used. The reason why programmers need to allocate memory themselves is that sometimes they cannot determine how much memory the program needs.

give an example

Announce
edit
For example, it is necessary to determine how much data is used through the query results of users or files or databases. At this time, the programmer cannot allocate the memory to a fixed amount when writing the program. At this time, the program must find available memory for itself when it runs. It must allocate memory in a dynamic way to write as follows:
int n; cout << "input n:"; cin >> n; cout << endl; int* iArray = new int[n]; for (int i = 0; i < n; i++) { cin >>iArray[i]; }