byte array size for read or write of filestream

  • Thread starter Thread starter news.microsoft.com
  • Start date Start date
N

news.microsoft.com

Hello,

what is the most performant size for the byte array for reading/writing
using 2 filestreams?

example code:

Dim bytearrayinput(4095) As Byte
Dim rdlen As Long = 0
Dim totlen As Long = fsInput.Length
Dim len As Integer

While (rdlen < totlen)
len = fsInput.Read(bytearrayinput, 0, 4096)
fsOutput.Write(bytearrayinput, 0, len)
rdlen = rdlen + len
End While


Grtz.
 
Hi,

Can you tell us why this is important, mostly the differences are so few
that thinking about it is complete culprit because the device it is sent to
makes the difference. By instance an ADSL line or a dialupline gives such a
difference that optimizing in the program has no sense. But probably you
have a reason.

Cor
 
It's when writing large files to disc (movies)
Is it better to do one big read and then one big write or like below?
 
Grtz,
In addition to the other comments:

| what is the most performant size for the byte array for reading/writing
| using 2 filestreams?

What is most performant for my machine is probably not most performant for
Cor's machine, nor your machine.

Any number of factors contribute to performance of reading & writing between
2 file streams, this includes but is not limited to:
1. Size & number of processors
2. Size, type & number of drive controllers (IDE, USB, SATA, ...)
3. Size, type & number of drives (hard drive, memory stick, floppy drive)
4. Amount of physical RAM
5. Amount of available virtual memory
6. Size of the files involved.
7. Size of the buffering internal to the filestream
8. Number of processes & threads currently executing (including type of
program)

Of course some of these factors more so then others. ;-)


Generally what I do is pick a large enough number that doesn't feel too
large. For example 32K or 64K, I might even consider 128K. If the
performance didn't "feel" right, I would pick another number. I would also
consider using Performance Monitor to see what the program is doing when
running the application with files that are the expected average size.


Conceptionally the program could be written to use performance counters to
monitor how performant it was itself, and adjust itself accordingly...



--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


| Hello,
|
| what is the most performant size for the byte array for reading/writing
| using 2 filestreams?
|
| example code:
|
| Dim bytearrayinput(4095) As Byte
| Dim rdlen As Long = 0
| Dim totlen As Long = fsInput.Length
| Dim len As Integer
|
| While (rdlen < totlen)
| len = fsInput.Read(bytearrayinput, 0, 4096)
| fsOutput.Write(bytearrayinput, 0, len)
| rdlen = rdlen + len
| End While
|
|
| Grtz.
|
|
 
Back
Top