Hi,

Which one is the fast way to open a file and read it. If possible
without buffers and any other kind of conversion. I need one step from the
harddisk to the Array.

Right now I am using FileStream. Is this the best way?

Thank you,
Roby Eisenbraun Martins

Re: Read File Fast by Jon

Jon
Sun Jun 05 15:15:22 CDT 2005

Roby Eisenbraun Martins
<RobyEisenbraunMartins@discussions.microsoft.com> wrote:
> Which one is the fast way to open a file and read it. If possible
> without buffers and any other kind of conversion. I need one step from the
> harddisk to the Array.
>
> Right now I am using FileStream. Is this the best way?

There are always going to be buffers at some level, but using
FileStream is likely to be as fast as you'll get in .NET. Do you have
any evidence that file reading is the bottleneck in your application?
Have you worked out how much slower your use of FileStream is than the
theoretical maximum transfer rate of your disk?

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Re: Read File Fast by Willy

Willy
Sun Jun 05 15:32:08 CDT 2005


"Roby Eisenbraun Martins" <RobyEisenbraunMartins@discussions.microsoft.com>
wrote in message news:FF6EB5DD-BDAF-47EF-9AD5-017B9BC7AD34@microsoft.com...
> Hi,
>
> Which one is the fast way to open a file and read it. If possible
> without buffers and any other kind of conversion. I need one step from the
> harddisk to the Array.
>
> Right now I am using FileStream. Is this the best way?
>
> Thank you,
> Roby Eisenbraun Martins

It will depend on the drive configuration, FileStream goes pretty fast on
single drives, but using striped disk arrays, you get better results when
doing un-buffered IO.
This can be achieved by using PInvoke to call CreateFile with the
FILE_FLAG_NO_BUFFERING flag specified, the handle returned can simply be
passed as argument to one of the FileStream constructors taking an handle to
a File.

Willy.




Re: Read File Fast by RobyEisenbraunMartins

RobyEisenbraunMartins
Sun Jun 05 16:16:01 CDT 2005

So is possible, but only using Windows API?

"Willy Denoyette [MVP]" wrote:

>
> "Roby Eisenbraun Martins" <RobyEisenbraunMartins@discussions.microsoft.com>
> wrote in message news:FF6EB5DD-BDAF-47EF-9AD5-017B9BC7AD34@microsoft.com...
> > Hi,
> >
> > Which one is the fast way to open a file and read it. If possible
> > without buffers and any other kind of conversion. I need one step from the
> > harddisk to the Array.
> >
> > Right now I am using FileStream. Is this the best way?
> >
> > Thank you,
> > Roby Eisenbraun Martins
>
> It will depend on the drive configuration, FileStream goes pretty fast on
> single drives, but using striped disk arrays, you get better results when
> doing un-buffered IO.
> This can be achieved by using PInvoke to call CreateFile with the
> FILE_FLAG_NO_BUFFERING flag specified, the handle returned can simply be
> passed as argument to one of the FileStream constructors taking an handle to
> a File.
>
> Willy.
>
>
>
>

Re: Read File Fast by Willy

Willy
Sun Jun 05 16:40:26 CDT 2005


"Roby Eisenbraun Martins" <RobyEisenbraunMartins@discussions.microsoft.com>
wrote in message news:0EB8DD12-FC4F-44EC-8A08-E85A599C7AAD@microsoft.com...
> So is possible, but only using Windows API?
>

Yep, but there is only the CreateFile API to "PInvoke", note that the FCL
also uses PInvoke to call the Win32 API's for file IO.
Note also that while you bypass the NTFS filesystem cache and consequently
avoids the overhead of moving data between the FS cache, the .NET cache and
the application space, you are also loosing the advantage of the FS cache
when multiple applications might read the same file or if the application
updates the file data. Some applications, like file copy programs or
databases, might take advantage of un-buffered IO while most others don't
need or want this at all.

Willy.

> "Willy Denoyette [MVP]" wrote:
>
>>
>> "Roby Eisenbraun Martins"
>> <RobyEisenbraunMartins@discussions.microsoft.com>
>> wrote in message
>> news:FF6EB5DD-BDAF-47EF-9AD5-017B9BC7AD34@microsoft.com...
>> > Hi,
>> >
>> > Which one is the fast way to open a file and read it. If possible
>> > without buffers and any other kind of conversion. I need one step from
>> > the
>> > harddisk to the Array.
>> >
>> > Right now I am using FileStream. Is this the best way?
>> >
>> > Thank you,
>> > Roby Eisenbraun Martins
>>
>> It will depend on the drive configuration, FileStream goes pretty fast on
>> single drives, but using striped disk arrays, you get better results when
>> doing un-buffered IO.
>> This can be achieved by using PInvoke to call CreateFile with the
>> FILE_FLAG_NO_BUFFERING flag specified, the handle returned can simply be
>> passed as argument to one of the FileStream constructors taking an handle
>> to
>> a File.
>>
>> Willy.
>>
>>
>>
>>



RE: Read File Fast by NoSpamMgbworld

NoSpamMgbworld
Mon Jun 06 09:30:06 CDT 2005

Do you have a performance issue when you are using FileStream?

If the answer is yes, you should search for a faster method, which will
likely entail poking into the Windows API. This will cause a small perf hit
with Interop, but you will likely gain it back with API file manipulation.

If no, streams are very lightweight and fast. I cannot, at present, think of
a faster "all .NET" solution.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************


"Roby Eisenbraun Martins" wrote:

> Hi,
>
> Which one is the fast way to open a file and read it. If possible
> without buffers and any other kind of conversion. I need one step from the
> harddisk to the Array.
>
> Right now I am using FileStream. Is this the best way?
>
> Thank you,
> Roby Eisenbraun Martins