Alex B
Alex B

Reputation: 84832

How to lock pages in memory using WinAPI?

I need to prevent application's memory pages from being swapped out of RAM on Windows. Is there a WinAPI function equivalent of POSIX mlockall() to achieve that?

Upvotes: 10

Views: 4991

Answers (3)

Ana Betts
Ana Betts

Reputation: 74652

I have to ask, why do you need to do this? If every app thought its pages were so important that they shouldn't be paged out ever, it would be a giant waste of memory.

If the pages are in use, they won't be sent to the pagefile, and if they're not in use, why keep them around? Trust in Mm, it was written by a very smart guy :)

Upvotes: 1

Hans Passant
Hans Passant

Reputation: 941625

Yes, VirtualLock(). There's a limit on how many pages you can lock, you can't hog RAM. Details are in the MSDN article.

Upvotes: 10

pipelinecache
pipelinecache

Reputation: 4024

Hi you can set the windows option of lock pages in memory. Usually this setting is mostly used by SQL Server, but works also for other applications. Check this site on msdn

enable addressing windows extensions (AWE) for your application. See this link on msdn

Upvotes: 0

Related Questions