Windows core programming learning notes-Chapter 13th

Source: Internet
Author: User

 

Try rendering, the most suitable way to explain: interspersed concepts in the process.

ProgramThe operation must be performed in the memory. So let's talk aboutWindowsMemory architecture.

WindowsThe memory architecture consists of virtual address space and memory.

Memory:

If every program runs directly occupies the memory, do you need to open an ice throne?1gMemory? Can you do anything else. The design of the virtual address space is simply a magic pen.

Assign4G (Pair32Bit System). A process directly operates on a virtual address space and transfers physical memory to it only when reading and writing data.

Relationship between physical memory and virtual memory: The physical memory corresponds to the virtual memory. DivisionOSOther programs do not directly access the physical memory, but access the virtual memory. The virtual memory can be equivalent to the physical memory. In the future, we will only talk about the memory, instead of the physical memory and virtual memory.

Relationship between page files and virtual memory: The virtual memory can be equivalent to the physical memory. Changing the page file size can change the virtual memory size. For details, page files only change the size of physical memory, but also the size of virtual memory.(Guess: The ing between physical memory and virtual memory is1:1.)Page files can be disabled, but virtual memory cannot be disabled.

The virtual address space corresponds to the physical address space: Virtual Address Space refers to the available address space range of the process. The physical address space refers to the actual available memory space range.

Virtual Address Space:

The virtual address space is also partitioned, and not all are available to users.

When the system creates a process and assigns it an address space, most of the available space is idle or unallocated. To use this part of address space, you must callVirtualallocTo allocate a region. The assignment region becomes a reservation. When booking an address space, the system will ensure that the starting address of the region is exactly an integer multiple of the allocation granularity, and the area size is exactly an integer multiple of the system page size.(Distribution granularity and system page size dataCPUDifferent.) VirtualfreeTo release the allocated region.

To use the reserved address space, you must allocate physical storage and map the storage to the reserved area. This process is called allocating physical storage. The transfer of physical storage is also carried out in the unit of page, just like in the pre-defined area. PassVirtualallocTo allocate physical storage,VirtualfreeTo release physical storage

Page Swap file:

TodayOSWhen the disk space is used as memory, the read/write speed is slow. Files on disks are generally called Page Swap files. Save part of the memory to the page swap file, and load the corresponding part of the page swap file into the memory when the application needs it.VirtualallocWhen the physical storage is transferred to the address space area, the space is actually allocated from the page swap file on the hard disk.

Physical storage not maintained in Page Swap files:

When a program is executed, the system opens the corresponding. ExeFile and calculateCodeAnd the data size. Then the system will reserve an address space and indicate that the physical storage associated with the region is. ExeFile itself. The system does not allocate space from the page swap file, but instead. ExeActual File Content(Or file Image)The address space area used for program reservation. In this way, not only is the loading program fast, but the Page Swap file size is also suitable.

When a program is located on a hard disk(That is,. ExeOrDLLFile)When used as the physical storage corresponding to the address space area, this file image is calledMemory ing File. When loading. ExeOrDLLThe system will automatically reserve the address space area and map the file image to this area. However, the system also provides a set of functions that allow developers to map data files to the address space.

Virtual Memory is the mechanism by which program code indirectly accesses the physical memory because it cannot directly access the physical memory. Or, more specifically, the virtual memory technology is to first reserve the virtual address space for the program, and then allocate physical memory to the virtual address space as needed, thus saving memory.

Summary:

References: click open link and click open link

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.