1. The stack is automatically allocated and released by the ‘compiler’ to store the ‘parameter values’ of the function, local variables, etc. A stack is a ‘system’ data structure and the corresponding ‘thread/process’ is unique. The advantage is fast and efficient, while the disadvantage is inflexible data ([FIFO]).

Stack space: statically allocated/dynamically allocated.

Static assignment — done by the compiler, such as auto assignment.

Dynamic allocation — done by alloc function. Memory is automatically released without manual release, and there is no release function. For the sake of portable programs, dynamic stack allocation is discouraged.

The heap is an area of memory that is allocated and released by the programmer himself. If the programmer does not release it, the program may end up being ‘recycled by the operating system’, as in iOS where alloc is stored in the heap. Advantages: flexible!! Data to adapt to a wide range of disadvantages :’ efficiency has been reduced ‘!!

The heap area is the internal data structure of the library, not necessarily unique. And the memory allocated by different heap areas is shielded from each other and cannot operate with each other. Also, there is no such thing as a static allocation of heap memory, it is’ dynamic ‘.

Although at the end of the program all the data space will be released back into the system, but: — — — — — — — — — — accurately ‘apply for and free memory match — — — — — — — — — — — — — is the basic requirement of a programmer.

3. Global area — also known as static area (stack). As the name implies, it is used to store both global and static variables.

Initialize global and static variables ———– in one area.

The uninitialized global and static variables ——— are in another area adjacent to each other.

At the end of the program, the system releases’ these two areas of memory ‘.

4. Text constant area :– store constant string, after the end of the program, the system released it.

5. Code area :– Store the binary code of — function.

For example:

int a = 10; Global area — Global initialization area.

char *p; Global region — Global uninitialized region.

main {

int b; — — — — — — — — — — the stack area

char s[] = “hello,world!” ; — — — — — — — — — — the stack area

char *p1; — — — — — — — — — the stack area

char *p2 = “hello!” ; ——– String Hello! In constant area, p2 is in stack area

stack int c = 0; ——– Global (statically allocated) initialization area

w1 = (char *)malloc(10);

w2 = (char *)malloc(20);

Ps: The allocated 10 – and 20-byte regions are in the heap

}