现在的位置: 首页 > 综合 > 正文

Program Memory Layout

2013年09月17日 ⁄ 综合 ⁄ 共 1592字 ⁄ 字号 评论关闭
Program Memory Layout

Memory is used for many purposes in a program. All memory looks the same to the processor: memory is just a big array of bytes, but programs partition this pool of bytes into different areas. Typically, a program will have the following sections:

  • Program Text: the machine code instructions that make up the application program are called program text. When there is hardware support for it, program text is often made read-only to prevent buggy programs from overwriting their own instructions by accident.
  • Initialized Data: any data that is given an initial value is organized in a contiguous section of memory so that it can be loaded efficiently along with the program text.
  • Uninitialized Data: global variables without initial values are placed at fixed addresses. Often, this entire area is initialized to zero. This data could be initialized to zero by making it part of the initialized data, but it would be wasteful to store a huge block of zeros in the program executable file on disk, and loading this data would not be as fast as simply writing zeros into a range of memory.
  • Heap Memory: a block of memory is allocated as heap memory. Small blocks of various sizes are allocated from this area at run time.
  • Shared Libraries: a section of memory is created for dynamically linked shared libraries. These contain additional machine code and data and will be discussed in Unit 6.
  • The Stack: contains activation records with return addresses and local variables for currently active function calls.
  • The Kernel: in some systems, the operating system or operating system kernel becomes part of an application's memory during system calls.
  • Page Zero: often, a section of memory starting at address zero is reserved and made unreadable to catch the common bug of trying to use a NULL pointer to access data.

Thus, the memory space seen by an application might look like the following:

Process memory

 

抱歉!评论已关闭.