In-depth understanding of daily C stack and stackEvery day, I picked up a C-language shell, which grew up and formed thousands of miles.
Today's shell: a deep understanding of heap and stack in memory. If you have a clear understanding of memory allocation, read [C parsing 3] C language memory allocation. Usage: stacks are automatically allocated by the system. For example, the system automatically opens up space for local variables in the stack. Heap is allocated by developers. For example, in C language, developers can use malloc to open up space in the heap, while in C ++, new is used.Direction: Stack: from high address to low address.Heap: The direction is from low address to high address.System: Stack: used by the SystemA piece of continuous memoryStack. The size of the entire continuous block of memory must be limited. Therefore, the stack size is generally limited. If the required stack space is too large, Stack Overflow may occur.Heap: heap space fromSystem idle memory linked list. Heap space can make non-sequential memory. Using the virtual memory mechanism of the operating system, a large space can be obtained.Speed: Stack: it is processed by the system and is fast.Heap: developers apply for use using malloc/new, which is slow and prone to problems such as memory fragmentation and Memory leakage.
Have a nice day!