Sravan Goud
Sravan Goud

Reputation: 113

Access File using FILE_FLAG_RANDOM_ACCESS with a limit on cache size

I want to access a file uisng using FILE_FLAG_RANDOM_ACCESS. But when a large file is accessed via FILE_FLAG_RANDOM_ACCESS, huge memory consumption could result in bad system performance. Is there a way to put a limit on cache size for a specific file handle?

Upvotes: 5

Views: 904

Answers (2)

Peter Ruderman
Peter Ruderman

Reputation: 12485

Windows doesn't provide a way to set a maximum cache size, but this is relatively easy to implement on your own. Open the file with FILE_FLAG_NO_BUFFERING and implement your own cache with an LRU list to determine when to evict blocks. Note that starting with Windows Server 2016, FILE_FLAG_RANDOM_ACCESS is less aggressive about retaining data in the cache, so this is less of a concern. Microsoft still recommends avoiding this flag, however.

Further reading: Troubleshoot Cache and Memory Manager Performance Issues

Upvotes: 2

ThomasMcLeod
ThomasMcLeod

Reputation: 7769

Yes there is a way to control file buffering in Windows but you will need to ditch the C++ standard library and use low-level OS file I/O APIs. If you are still interested, start reading here: http://msdn.microsoft.com/en-us/library/windows/desktop/aa365199(v=vs.85).aspx

Upvotes: 0

Related Questions