Question

I want to implement interpolation search on large array. One of the possible optimizations is to touch memory addresses that is already loaded into main memory first (touching them doesn't cause hard page fault). For example, if I need to read data at index X, I can check whether this page is in main memory, if it's not - I can check one of the adjacent pages that is already in the memory.

So, I need some mechanism to check that page at address (X & 0xFFFFFFFFFFFE0000) is loaded (or not). Or better - I need to get list of loaded pages within some address range, or something like that.

Is it possible in user-space code on linux or windows (app is crossp-latform)? At this moment I just use LRU cache of recent touched memory addresses in hope that operating system doesn't swap recently used memory pages.

Was it helpful?

Solution

In Win32 Api

Take a look at QueryWorkingSet function to query the state of the memory of your process.

As an efficient way to load pages on physical memory see PrefetchVirtualMemory

The lowest level, cross-platform API compatible with Windows and Linux that I know is POSIX specification.

Also I recomend you to take a look on numa Win32 memory functions and intel cache line and L2 memory opcodes, It is a very tricky stuff but it could increment heavily the performance of memory reads/writes (if this is the main objective).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top