In that year, I learned Linux C-Huawei interview question variable step by step

Source: Internet
Author: User


Reprinted please indicate the source: http://blog.csdn.net/muge0913/article/details/7313859


Huawei interview questions:

Local variables of the program exist in (stack), global variables exist in (static zone), and dynamic application data exist in (HEAP.


Summary:


1. the most impressive thing about the stack is the uboot porting. When you are about to enter the C code, you must give the C code a good runtime environment, one of the important items is to set the stack.


2. Differences and processes between static memory allocation and dynamic memory allocation

1) static memory allocation is completed at compilation without occupying CPU resources; dynamic memory allocation is completed at runtime, and dynamic memory allocation and release require occupying CPU resources;

2) Static Memory is allocated on the stack, and dynamic memory is allocated on the stack;

3) dynamic memory allocation requires support for pointers or reference data types, while static memory allocation is not required;

4) for static memory allocation, the size of the memory block needs to be determined before compilation, while for dynamic memory allocation, the size of the memory block is determined before compilation. The size of the memory block is determined based on the runtime environment, allocate memory as needed. In this case, static memory is allocated as planned, and dynamic memory is allocated as needed.

5) in static memory allocation, the control of the memory is handed over to the compiler, while the control of the dynamic memory is handed over to the programmer;

 

To sum up, static memory allocation is suitable for determining the amount of memory to be occupied during compilation, while dynamic memory allocation can be used when the memory demand cannot be determined during compilation; however, static memory allocation is more efficient than dynamic memory allocation, because dynamic memory allocation and release require additional overhead. The level of dynamic memory management relies heavily on the level of programmers, improper processing may cause memory leakage.


 

 

 

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.