Size of Byte Array for big files?

A

Anil Gupte

I am using the following:
Dim fsReadStream As New FileStream(TextBoxVideoFileName.Text, FileMode.Open,
FileAccess.Read)
Dim brReader As New BinaryReader(fsReadStream)
Dim ByteArray() As Byte

ByteArray = brReader.ReadBytes(fsReadStream.Length)

This works fine for smaller files, but crashes with an overflow exception
with a large file (2.5GB). Is the size of the array a problem? How can I
change it? Any other solution?

Thanx,
 
P

Patrice

AFAIK arrays are indexed using an integer whose max value allows for 2 Go.

Even for smaller files it's likely better to avoid loading a whole file in
memory unless this is strictly needed and especially if those files are not
limited in size. A common practice is to read a file in "chunks" so that you
consume only the size of a buffer that holds the current "access window" on
file data...

So it would depend what you are doing once the whole file is loaded in
memory....
 
G

Guest

This works fine for smaller files, but crashes with an overflow
exception with a large file (2.5GB). Is the size of the array a
problem? How can I change it? Any other solution?

Yes, you're creating a 2.5GB array in memory. I believe there is a 2GB
limit?

You should stream the file using a smaller array as data is needed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top