meha0250
meha0250

Reputation: 203

windows memory managment: check if a page is in memory

Is there a way, in Windows, to check if a page in in memory or in disk(swap space)? The reason I want know this is to avoid causing page fault if the page is in disk, by not accessing that page.

Upvotes: 2

Views: 243

Answers (2)

samsquanch
samsquanch

Reputation: 531

The whole point of Virtual Memory is to abstract this sort of thing away. If you are storing your own data and in user-land, put it in a data-structure that supports caching and don't think about pages.

If you are writing code in kernel-space, I know in linux you need to convert a memory address from a user-land to a kernal-space one, then there are API calls in the VMM to get at the page_table_entry, and subsequently the page struct from the address. Once that is done, you use logical operators to check for flags, one of which is "swapped". If you are trying to make something fast though, traversing and messing with memory at the page level might not be the most efficient (or safest) thing to do.

More information is needed in order to provide a more complete answer.

Upvotes: 0

Bukes
Bukes

Reputation: 3718

There is no documented way that I am aware of for accomplishing this in user mode.

That said, it is possible to determine this in kernel mode, but this would involve inspecting the Page Table Entries, which belong to the Memory Manager - not something that you really wouldn't want to do in any sort of production code.

What is the real problem you're trying to solve?

Upvotes: 2

Related Questions