Forwarding: How Windows manages memory

Source: Internet
Author: User

(1) There are three ways: virtual memory, memory mapped file, memory stack.

Virtual memory is the loading of page files into memory and is suitable for larger objects or structures;

A memory-mapped file is a memory-sharing process that loads files on disk into memory for large files and single machines;

The stack is the dynamic allocation of memory, suitable for the creation of small objects.

These are described in detail in Windows core programming.

(2) When the process wants to read the data in its own virtual address space:

if (data in physical memory)
{
Virtual address converted to physical address
Read data
}
Else
{
if (data on disk)
{
If (physical memory is still idle)
{
Read data from disk to physical memory
Virtual address converted to physical address
Read data
}
Else
{
To deposit data from a page in physical memory to disk
Read the data from the disk to the physical memory of the page
Virtual address converted to physical address
Read data
}
}
Else
{
Error
}
}

(3) When the program runs, it needs to read out the code of the program from memory.

The location of the code must be in physical memory to be able to be run, because the current operating system has a very many programs running, memory can not be completely put down, so the concept of virtual memory. Put the unused pieces of the program into the virtual memory, when needed to use it in the load master (physical memory). This is what memory management needs to do. Memory management There's another thing to do: compute the physical location of the program fragment in main memory for CPU scheduling.

Memory management is block-managed, page-managed, forged, and forged-page-managed. Now commonly used things forged page management block management: The main memory is divided into a chunk, a large chunk, when the required program fragment is not in main memory to allocate a piece of main memory space, the program fragment load into the storage, even if the required program slice only a few bytes can be assigned to it. This creates a lot of waste, with an average of 50% of memory wasted, but easy to manage.

Page management: The main memory is divided into one page, each page of space is much smaller than a piece of space, it is obvious that the space utilization of this method is much higher than the block-type management.

Segment management: The main memory is divided into a paragraph, each section of space and a page more than one page of space, this method in space utilization is much higher than page management, but there is another disadvantage. A program fragment may be divided into dozens of segments, so that a lot of time will be wasted on computing the physical address of each segment (the computer is the most time-consuming people know that I/O bar ).

Forged Page Management: combines the benefits of segment management and page management. The main memory is divided into several pages, and each page is divided into several paragraphs. The benefits are obvious, so I don't have to say more.

Various memory management have its own method to calculate the program fragment in main memory physical address, in fact, are very similar.

Virtual Memory:

1) for a computer, the size of the physical memory is the size of the memory bars that are inserted on the motherboard, and for the CPU, the size of the physical memory is the address line addressable size on the CPU.

2) virtual memory is the data area that is created when a program is run, it may be larger than physical memory, and it is an abstraction of memory management.

3) Because virtual memory is likely to be larger than physical memory, the operating system uses a memory paging mechanism that divides virtual memory into pages (page), divides physical memory into multiple page frames (page frame), and the size of pages and page frames. The virtual memory pages that are now used will be mapped to the physical memory page frames through the page table, and it is clear that the maximum range of real-time mappings is the size of the physical memory. If you are using a virtual memory page that is not in this mapping, the operating system invalidates one of the less-used page frames and stores the contents of the page frame in another medium (such as a disk), and then maps the physical memory of the page frame and the virtual memory pages that require space.

4) The virtual memory address consists of the page number (associated with the page number in the page table) and the offset.

Forwarding: How Windows manages memory

Related Article

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.