So, when we reference a committed page for the first time, one page in physical memory is located and those addresses (one in virtual address space and one in physical address space) are connected in page entry. Now, since every application has to use virtaul memory and go through that layer, it is theoretically possible to move memory without actually copying every byte. What I mean is to change the address of page in virtual address space. So, for example, if one page entry says: "Hey, 11-th page in physical memory is associated with 156-th page in virtual space of process with ID 1001", and I want to move 156-th page to 169-th page, can I change this page entry to say: "Hey, 11-th page in physical memory is associated with 169-th page in virtual space of process with ID 1001". Does Windows or Linux operating system offer a function that I can use to do so?
2 Answers
Your question is a good one but suffers from a bit of a mismatch.
In general: The management of virtual memory address translation is an operating system level task, not a compiler or application level activity. In fact, most operating systems go to great lengths to make the process transparent. As such language does not really come into this.
Now, if the operating system you use supports this sort of memory address relocation the most obvious approach would be to encapsulate this OS function in a C++ entity, like a method in an existing OS interface class, or a new class.
Now, if you have sample code for the OS calls needed, the topic becomes "How do I encapsulate this bit of code in C++?" Which opens up a discussion of C++ and OOP techniques.
On the other hand, if you do not know the OS calls needed, this leads to a question about the specific OS in which you wish to accomplish this task? which opens up an OS and memory management discussion.
The application has no knowledge whatsoever of physical memory and which page frame a logical page is mapped to. It is entirely possible (and occurs frequently) for the logical page to physical page mapping to change as a program executes.
On some systems it is possible to map multiple logical pages to the same physical page. However, the application cannot control which physical page it is mapped to.