Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passthru reading of all files in folder

Tags:

c#

.net

ntfs

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

like image 937
Martin Zugec Avatar asked Jun 25 '13 12:06

Martin Zugec


2 Answers

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.

like image 147
Nick Avatar answered Sep 30 '22 11:09

Nick


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.

like image 20
Robert Goldwein Avatar answered Sep 30 '22 11:09

Robert Goldwein