Filestream Out of Memory Error
Posted on 2004-04-26
I am running VB.NET my machine has 2GB of ram. My program extracts and sorts large amounts of financial data (1.5GB+). I have tried using the filestream and stremreader methods. I consistantly recieve 'System.OutOfMemoryException'. I have duplicated this error on blank form with only a command button containg the code. I hit the button after each iteration (replicating the loop in my program) and watch the RAM in the task manager keep going up until it hits the 2GB marker, then I receive the out of memory exception.This happens 9/10 times. Sometimes the ram gets to about 1.5GB then the system finally releases the unused resources. There is no pattern or set amount of time to when it decides to finally realease the unused resources. It seems like the OS isn't receiving the message to release the data. The file tradefile.l is 385MB. It is from the New York Stock Exchange TAQ Database and was obtained via FTP. I ran this code using the FSO in VB 6.0 without error for months. I would rather use the filestream method because it is about 5X faster than the FSO. Thank You.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim s As String
Dim readBytes(91000000) As Byte
Dim fsstream As New FileStream("D:\TRADE DATA\TESTING\TEMP _
FILES\tradefile.l", FileMode.Open, FileAccess.Read)
fsstream.Read(readBytes, 0, 90999999)
s = System.Text.Encoding.ASCII.GetString(readBytes)
s = ""