Program memory allocation

 

Program memory allocation

Portions of the program in the memory allocation as shown below:

 

First to familiarize yourself with , several important concepts appear on the map.

Heap : at run time (rather than at compile time) allocated memory space

Stack: local variables assigned to run the function, the function parameters, return data, and return the allocated memory address.

 Code area: static code in memory storage area. All class member function or a non-member function of the code.

Global data: the program at compile time, it has been initialized or assigned global variables, constants and static data .

 

Usually defined an array, regardless of the array is local (stack allocated) or global (assigned in the global data area), its size in the program are already aware of. Because of the size of the array must be declared by a constant.

However, when writing programs, and can not always determine the size of the array of need, you need to acquire memory from the system at runtime.

Size of the program at compile time and link this need can not be determined in order to determine the time and get the program running memory space. This memory needs to run the program as possible but sometimes big, sometimes small, the memory of this application at run time is the heap memory.

Stack may be seen as resource allocation or memory pool according to the requirements.

Array name itself (not within square brackets and subscript), is actually a memory address indicating the first address of the array where the memory storage space. And has a memory pointer can be seen as an array, and is located in the stack memory array, and the nature and function is located in the stack array is the same.

 

Reproduced in: https: //www.cnblogs.com/zhangshufeng/archive/2011/10/11/2207756.html

Guess you like

Origin blog.csdn.net/weixin_33795093/article/details/93532294