Results 1 to 5 of 5

Thread: out of memory during a loop of txt file

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,580

    out of memory during a loop of txt file

    I use this routine to read txt file line by line...

    i loop approx 123 files each file are of 45/80 MB. (approx 358.000 line per file)

    i use (pseudo code):

    ...
    for each file in my dir

    TEST1(name_file )

    next
    ...

    Sub TEST1(name_file )

    Dim temp As String
    Dim MyArray() As String
    Dim FileID As Integer

    FileID = FreeFile
    Open "C:\TEST\" & name_file For Binary Access Read As #FileID
    temp = Space(LOF(FileID))
    Get #FileID, , temp
    Close #FileID

    Erase MyArray()
    MyArray() = Split(temp, vbNewLine)

    temp = ""
    Dim X As Long

    For X = LBound(MyArray()) To UBound(MyArray())
    temp = MyArray(X) 'Is the; current; Line
    Next

    End Sub


    but after the 3thfile processed have Out of Memory!!!!

  2. #2
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: out of memory during a loop of txt file

    Try the file mapping technique demonstrated in Treat a file like an array without reading to memory.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,580

    Re: out of memory during a loop of txt file

    Quote Originally Posted by Bonnie West View Post
    Try the file mapping technique demonstrated in Treat a file like an array without reading to memory.
    ok tks!!!!

    but in wich part of code i can loop "line by line" the array.... similar:

    Dim X As Long

    For X = LBound(MyArray()) To UBound(MyArray())
    temp = MyArray(X) 'Is the; current; Line
    Next

  4. #4
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: out of memory during a loop of txt file

    Can you post the relevant parts of your code? Your current For loop will have to be modified to properly work with that technique.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  5. #5
    Lively Member
    Join Date
    May 2009
    Location
    UK
    Posts
    68

    Re: out of memory during a loop of txt file

    Quote Originally Posted by luca90 View Post
    I use this routine to read txt file line by line...

    i loop approx 123 files each file are of 45/80 MB. (approx 358.000 line per file)

    ...

    but after the 3thfile processed have Out of Memory!!!!

    You could look into changing some string to currency ?

    clear some variables = null

    look into converting dos/linux crlf/lf formatting required with some files.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width