views:

134

answers:

2

How would one go about keep an object in memory such that it won't be paged out by the OS in .Net?

i.e. Something similar to VirtualLock, but operating on an object, such that if compacting occurs and the object is moved it still would not be paged out, etc.. (I suppose one could pin the object's, determine what pages it belongs to, and then VirtualLock those pages, but that seems non-desireable for many reasons.)

If possible, could you point me to a reference or working sample? (C# ideally)

Many thanks in advance!

+2  A: 

Have you looked at this one http://www.codeplex.com/NonPagedCLRHost ?

Andrei Taptunov
That's interesting, but we wouldn't want to use a custom host. Anything similar for standard .Net?
Gene
+1  A: 

If you want deterministic response times you should use a real time OS that operates with the limits you specify, not Windows.

By definition, if they are infrequently used, the are high on the list of candidates to be paged out.

Here is a horrible solution: Create a thread (or an asynchronous timer) that once ever INTERVAL ms touches your object then goes back to sleep. Tune INTERVAL until you get the desired behaviour.

Stephen Kellett
+1 for solution: this is good as it gets if you must stick with managed code *and* you don't want to use a custom CLR host.
Chris O