I am not saying that you want to do this, or that this is best practice, but you may find that it works well enough for you. It seems to match what you requested.
Summary On each page in the process, on the page, click regularly.
How about a thread that runs in the background and wakes up every N seconds. Each time a page wakes up, it tries to read the address X. The attempt is protected by an exception handler if you read a bad address. Then increase X by page size.
There are 65536 pages in 4 GB, 49152 pages in 3 GB, 32768 pages in 2 GB. Divide your downtime (night dead time) by how often you want (try) to hit each page.
BYTE *ptr; ptr = NULL; while(TRUE) { __try { BYTE b; b = *ptr; } __except(EXCEPTION_EXECUTE_HANDLER) {
You can get the sizeOfVMPage value from the dwPageSize value in the return result from GetSystemInfo ().
Do not try to avoid the exception handler using if (! IsBadReadPtr (ptr)), because other threads in the application can simultaneously change memory protection. If you peel off, because of this, it is almost impossible to determine why (most likely, this will be a disjoint state of the race), so do not waste time on it.
Of course, you want to disable this thread during the day and only start it during your dead time.
Stephen kellett
source share