Re: Optimal Buffer Size To Read A File
From: Jon Skeet [C# MVP] (skeet_at_pobox.com)
Date: 12/19/04
- Next message: bubbakittee: "using "using" to fake typedefs"
- Previous message: Jon Skeet [C# MVP]: "Re: Is this thread safe?"
- In reply to: Amy L.: "Optimal Buffer Size To Read A File"
- Next in thread: Amy L.: "Re: Optimal Buffer Size To Read A File"
- Reply: Amy L.: "Re: Optimal Buffer Size To Read A File"
- Messages sorted by: [ date ] [ thread ]
Date: Sun, 19 Dec 2004 08:49:01 -0000
Amy L. <amyl@paxemail.com> wrote:
> Is there a Buffer size that is optimial based on the framework or OS that is
> optimal when working with chunks of data? Also, is there a point where the
> buffer size might not be optimal (too large)? I am considering an 8K or 16K
> Buffer. The files sizes are random but range between 8K - 100K with the
> occasional files being several megs.
>
> Example:
>
> int _READBUFFER_ = 1024 ;
> fi = new FileInfo( args[ 0 ] ) ;
> FileStream fs = fi.OpenRead() ;
> while ( fs.Read( ByteArray, 0, _READBUFFER_ ) > 0 )
> {
> myStringBuilder.Append( textConverter.GetString( ByteArray ) ) ;
> }
"Optimal" depends on where you draw the line between time and memory.
The larger the buffer, the faster - but the more expensive in terms of
memory.
Note that your code above is broken, as it doesn't use the value
returned by Read to make sure that only that amount of data is
converted by the text converter.
-- Jon Skeet - <skeet@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
- Next message: bubbakittee: "using "using" to fake typedefs"
- Previous message: Jon Skeet [C# MVP]: "Re: Is this thread safe?"
- In reply to: Amy L.: "Optimal Buffer Size To Read A File"
- Next in thread: Amy L.: "Re: Optimal Buffer Size To Read A File"
- Reply: Amy L.: "Re: Optimal Buffer Size To Read A File"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|