Heap memory stack memory virtual memory dynamic memory management

Source: Internet
Author: User

From the compiler perspective, memory is divided into three situations:

1. The memory area that has been determined during system initialization and will not change. It generally refers to global variables and static variable arrays.

2. memory on the stack: generally refers to the local variables in the function. The memory is allocated during function calling. After the call is completed, the system automatically releases the memory and does not need to be recycled by itself. This is highly efficient. Sometimes the stack needs to be set by yourself. Improper settings can cause stack overflow.

3. heap memory: the memory allocated by the dynamic allocation function is the heap memory. It is suitable for scenarios where MMU (memory management) is available and you are not sure about the memory size to be applied. Note: after using the dynamic memory allocation function, you must release the memory in time and clear the pointer to 0. Otherwise, the wild pointer and Memory leakage may occur. Because the system is not responsible for release. At the same time, frequent calls can also easily cause random memory, which involves memory fragment and recovery algorithms.

Virtual Memory and direct operation memory:

Embedded systems generally have limited resources. Generally, developers directly partition the memory. For memory operations, developers need to understand the overall usage of the memory. During system initialization, UCOS divides the memory into several fixed buffer pools. The task application memory applies for memory from a buffer pool and is released back to the memory pool after use.

PC generally has rich resources. Upper-layer application developers use virtual memory to block the underlying physical memory address.

Pointer array and stack:

Pointers are language tools, and dynamic allocation functions are all operated by pointers.

Arrays and stacks belong to the data structure. For arrays with small data volumes and fixed storage structures that can use static storage structures, function calls are generally stack operations. Note that stack settings should be reasonable. Avoid stack depth insufficiency, resulting in parameter loss during calls; stack depth is too deep, resulting in lower efficiency.

Heap memory stack memory virtual memory dynamic memory management

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.