Loading bin files to memory

itemize

New member
Joined
Jun 6, 2007
Messages
1
Programming Experience
1-3
Hi all.

I need to load data from 30 .bin files 4000Kb each and store them in some temp structures to use them (one by one). So I created a class where I have

VB.NET:
Public Function ApriFileCSV(ByVal sFlName As String) As Boolean

        On Error GoTo Err_Init
        sFileCSV = sFlName
         input = New FileStream(sFlName, FileMode.Open, FileAccess.Read, FileShare.None, 8, FileOptions.Asynchronous)
        myReader = New BinaryReader(input)

        ReDim Preserve readstat(0 To Me.numrighe - 1)

        Return True

        Exit Function

Err_Init:
        Err.Clear()
        Return False

    End Function

and then I work directly with myReader to extract data. It's quite a long operation, because I'm working with the files I suppose. Is there a way to load one file to memory, work with it, close it and then open another file..and so on? I think it can be faster.

I tried using MemoryStream:

VB.NET:
 Public Function xxxApriFileCSV(ByVal sFlName As String) As Boolean

        On Error GoTo Err_Init
        sFileCSV = sFlName

        st = New MemoryStream(5000)

        Dim bw As New BinaryWriter(st)

        'input = New FileStream(sFlName, FileMode.Open, FileAccess.Read)
        input = New FileStream(sFlName, FileMode.Open, FileAccess.Read, FileShare.None, 8, FileOptions.Asynchronous)
        myReader = New BinaryReader(input)

 'Open a streamreader with the file name from the dialog
        Dim myStreamReader As New StreamReader(sFlName)
        'Read the file with the streamreader
        Dim myFileContents As String = myStreamReader.ReadToEnd()
        'Close the streamreader - it uses resources
        myStreamReader.Close()
        'Set the output fields
        bw.Write(myFileContents)

...

but it seems I have to read the file and write it to memory, so I'm back to the problem. I'm searching for something that load directly my file to ram.

Hope I've been clear.
 
Last edited by a moderator:
Back
Top