I've got pretty unusual request: I would like to load all files from specific folder (so far easy). I need something with very small memory footprint.

Now it gets complicated (at least for me). I DON'T need to store or use the content of the files - I just need to force block-level caching mechanism to cache all the blocks that are used by that specific folder.

I know there are many different methods (BinaryReader, StreamReader etc.), but my case is quite special, since I don't care about the content...

Any idea what would be the best way how to achieve this?

Should I use small buffer? But since it would filled quickly, wouldn't flushing of the buffer actually slow down the operation?

Thanks, Martin

有帮助吗?

解决方案

I would perhaps memory map the files and then loop around accessing an element of each file at regular (block-spaced) intervals.

Assuming of course that you are able to use .Net 4.0.

In psuedo code you'd do something like:

using ( var mmf = MemoryMappedFile.CreateFromFile( path ) )
{    
    for ( long offset = 0 ; offset < file.Size ; offset += block_size )
    {
        using ( var acc = accessor = mmf.CreateViewAccessor(offset, 1) )
        {
            acc.ReadByte(offset);
        }
    }
}

But at the end of the day, each method will have different performance characteristics so you might have to use a bit of trial and error to find out which is the most performant.

其他提示

I would simply read those files. When you do that, CacheManager in NTFS caches these files automatically, and you don't have to care about anything else - that's exactly the role of CacheManager, and by reading these files, you give it a hint that these files should be cached.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top