Results 1 to 28 of 28

Thread: Hopeless: memory not being released

Hybrid View

  1. #1

    Thread Starter
    Hyperactive Member TupacShakur's Avatar
    Join Date
    Mar 2002
    Location
    Da Land Of Da Heartless...
    Posts
    493

    Re: Hopeless: memory not being released

    Quote Originally Posted by Bill Crawley
    You should drop the use of using DOS based file I/O and make a reference to the microsoft Scripting Runtime. This is much more efficient and feature rich.
    How is that, i am not sure what are you talking about. Maybe u can help me a bit further. Thanks .
    "And Now I'm Lika Major Threat, Cause I Remind U Of The Things U Were Made To Forget!" - (2PAC)

    "Now They Label Me a Lunatic, Couldn't Care Less, Death or Success is What I Quest, Cause I'm Fearless!" - (2PAC)

    " There's a light at the end of every tunnel, just pray it's not a train!! "



    I am 100% addicted to Tupac. What about you?
    I am 24% addicted to Counterstrike. What about you?
    The #1 Tupac Fans Web Site | The Official Tupac Web Site

  2. #2
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: Hopeless: memory not being released

    TupacShakur, Are you sure you have the latest VB6.0 Service Pack (SP6) ?

  3. #3
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: Hopeless: memory not being released

    Can you post your complete code, this is beginning to sound like the code has other problems than the part of the code you're talking about. I guess like this because I've done a splitting program myself in the past that processed a bigger file. It was simple and efficient enough.

    Comintern: but Preserve is still faster than without in many many cases, because without Preserve the ReDim must clear all bytes to zero. I've tested the speed difference of ReDim and have seen there really is difference in using Preserve.

  4. #4

    Thread Starter
    Hyperactive Member TupacShakur's Avatar
    Join Date
    Mar 2002
    Location
    Da Land Of Da Heartless...
    Posts
    493

    Re: Hopeless: memory not being released

    CVMichael: I'm not sure, how can i know which SP i got, and how much does it have to do with my problem?

    Merri: Actually, i am pretty much sure that my code has no problems. The rest of my code is pretty much irrelevant, but i went through it all so many times, that i'm sure it's all fine. The problem seems to be in how VB allocates and deallocates memory, specially in a long loop (in my case). What environment did u test/use ur program in?
    "And Now I'm Lika Major Threat, Cause I Remind U Of The Things U Were Made To Forget!" - (2PAC)

    "Now They Label Me a Lunatic, Couldn't Care Less, Death or Success is What I Quest, Cause I'm Fearless!" - (2PAC)

    " There's a light at the end of every tunnel, just pray it's not a train!! "



    I am 100% addicted to Tupac. What about you?
    I am 24% addicted to Counterstrike. What about you?
    The #1 Tupac Fans Web Site | The Official Tupac Web Site

  5. #5
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Hopeless: memory not being released

    I have faith in merri. I gave him the link to this thread. He can fix it.

  6. #6
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: Hopeless: memory not being released

    Quote Originally Posted by TupacShakur
    CVMichael: I'm not sure, how can i know which SP i got, and how much does it have to do with my problem?
    Memory leaks, sounds like a bug in VB, I remember I had the same problem in the past with de-allocating memory, and I fixed the problem when I installed the new Service Pack.

    To check what Service Pack you have:
    First, it shows in the spash screen when you start VB6.0
    Second, if you click on "Help" then "About Microsoft Visual Basic...", you will see something like "Microsoft Visual Basic 6.0 (SP6)" where (SP#) is the number of your service pack.

    Service Pack 6 is the latest...

    If you don't have the latest, you can get it from microsoft.com searching for "visual basic service pack"
    Actually, I looked it up, and here is the link:
    http://www.microsoft.com/downloads/d...DisplayLang=en

  7. #7
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: Hopeless: memory not being released

    Quote Originally Posted by TupacShakur
    i am pretty much sure that my code has no problems.
    This made me laugh, just the other day I read "programmer's famous last words" and this line here is word-to-word perfect on the list

    Anyways, here is the code I used. I seem to have no VB6 service pack installed according to the about box, though I do have the newest runtime files and maybe some other. About the code, all it has is a form with a single command button which can be clicked. The program then automatically splits a huge SQL file into pieces which can be used rebuild an SQL database a piece at a time to let server have some breath.

    VB Code:
    1. Option Explicit
    2.  
    3. Const Filename = "E:\tempfile"
    4. Const vbMEGABYTE As Long = 2097152
    5.  
    6. Dim Quit As Boolean
    7. Private Sub Command1_Click()
    8.     Dim Filesize As Long, Counter As Long, A As Long
    9.     Dim ReadBuffer() As Byte, TempBuffer() As Byte, EndPos As Long
    10.  
    11.     ReDim ReadBuffer(vbMEGABYTE - 1)
    12.  
    13.     Filesize = FileLen(Filename)
    14.    
    15.     Open Filename For Binary Access Read As #1
    16.         Do While (Filesize - Seek(1)) \ vbMEGABYTE
    17.             Counter = Counter + 1
    18.             Open Filename & "_" & Format$(Counter, "00") & ".sql" For Binary Access Write As #2
    19.                 If Not ((Not TempBuffer) = True) Then Put #2, , TempBuffer
    20.                 Get #1, , ReadBuffer
    21.                 EndPos = InBArrRev(ReadBuffer, "INSERT INTO ")
    22.                 ReDim Preserve TempBuffer(vbMEGABYTE - EndPos - 1)
    23.                 For A = EndPos To vbMEGABYTE - 1
    24.                     TempBuffer(A - EndPos) = ReadBuffer(A)
    25.                 Next A
    26.                 ReDim Preserve ReadBuffer(EndPos - 1)
    27.                 Put #2, , ReadBuffer
    28.                 ReDim Preserve ReadBuffer(vbMEGABYTE - 1)
    29.             Close #2
    30.             Command1.Caption = Format$((Seek(1) / Filesize * 100), "0.00") & " %"
    31.             DoEvents
    32.             If Quit = True Then Close #1: Unload Me
    33.         Loop
    34.         Counter = Counter + 1
    35.         ReDim Preserve ReadBuffer(Filesize - Seek(1) - 1)
    36.         Get #1, , ReadBuffer
    37.         Open Filename & "_" & Format$(Counter, "00") & ".sql" For Binary Access Write As #2
    38.             Put #2, , TempBuffer
    39.             Put #2, , ReadBuffer
    40.         Close #2
    41.     Close #1
    42.     Command1.Caption = "Done!"
    43. End Sub
    44.  
    45. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    46.     Quit = True
    47. End Sub

    Then the helper function module:

    Code:
    Option Explicit
    
    Public Function InBArrRev(ByRef ByteArray() As Byte, ByRef KeyWord As String, Optional StartPos As Long = -1, Optional Compare As Byte = vbBinaryCompare) As Long
        Static KeyBuffer() As Byte, KeyBufferU() As Byte, KeyPtr As Long, OldCompare As Byte
        Dim A As Long, B As Long, C As Long, KeyLen As Long, KeyUpper As Long
        Dim FirstKeyByte As Byte, LastKeyByte As Byte, TempByte As Byte
        Dim FirstKeyByteU As Byte, LastKeyByteU As Byte
        If KeyWord = vbNullString Then InBArrRev = -1: Exit Function
        KeyLen = StrPtr(KeyWord)
        If Not (KeyPtr = KeyLen And Compare = OldCompare) Then
            KeyPtr = KeyLen
            OldCompare = Compare
            If Compare = vbBinaryCompare Then
                KeyBuffer = KeyWord
            Else
                KeyBufferU = UCase$(KeyWord)
                KeyBuffer = LCase$(KeyWord)
            End If
        End If
        KeyLen = UBound(KeyBuffer) - 1
        KeyUpper = KeyLen \ 2
        If KeyUpper > UBound(ByteArray) Then InBArrRev = -1: Exit Function
        If StartPos < 0 Or StartPos > UBound(ByteArray) - KeyUpper Then StartPos = UBound(ByteArray) - KeyUpper
        FirstKeyByte = KeyBuffer(0)
        LastKeyByte = KeyBuffer(UBound(KeyBuffer) - 1)
        If Compare = vbBinaryCompare Then
            'loop through the array
            For A = StartPos To 0 Step -1
                If ByteArray(A) = FirstKeyByte Then
                    If ByteArray(A + KeyUpper) = LastKeyByte Then
                        If KeyLen > 4 Then
                            'check if keyword is found from the array
                            C = A + 1
                            For B = 2 To KeyLen Step 2
                                If Not (ByteArray(C) = KeyBuffer(B)) Then Exit For
                                C = C + 1
                            Next B
                            'keyword is found!
                            If B > KeyLen Then
                                InBArrRev = A
                                Exit Function
                            End If
                        Else
                            InBArrRev = A
                            Exit Function
                        End If
                    End If
                End If
            Next A
        Else 'vbTextCompare
            FirstKeyByteU = KeyBufferU(0)
            LastKeyByteU = KeyBufferU(UBound(KeyBuffer) - 1)
            'loop through the array
            For A = StartPos To 0 Step -1
                TempByte = ByteArray(A)
                If TempByte = FirstKeyByte Or TempByte = FirstKeyByteU Then
                    TempByte = ByteArray(A + KeyUpper)
                    If TempByte = LastKeyByte Or TempByte = LastKeyByteU Then
                        If KeyLen > 4 Then
                            'check if keyword is found from the array
                            C = A + 1
                            For B = 2 To KeyLen Step 2
                                TempByte = ByteArray(C)
                                If Not (TempByte = KeyBuffer(B) Or TempByte = KeyBufferU(B)) Then Exit For
                                C = C + 1
                            Next B
                            'keyword is found!
                            If B > KeyLen Then
                                InBArrRev = A
                                Exit Function
                            End If
                        Else
                            InBArrRev = A
                            Exit Function
                        End If
                    End If
                End If
            Next A
        End If
        InBArrRev = -1
    End Function
    I never meant this code to be seen by others so it is uncommented. The file I split was over 600 MB in size.

  8. #8

    Thread Starter
    Hyperactive Member TupacShakur's Avatar
    Join Date
    Mar 2002
    Location
    Da Land Of Da Heartless...
    Posts
    493

    Re: Hopeless: memory not being released

    Quote Originally Posted by CVMichael
    To check what Service Pack you have:
    First, it shows in the spash screen when you start VB6.0
    Second, if you click on "Help" then "About Microsoft Visual Basic...", you will see something like "Microsoft Visual Basic 6.0 (SP6)" where (SP#) is the number of your service pack.
    Actually, i checked the splash screen and the about dialog before asking where to find the SP version, but they doent say anything in my case. Anyway, thanks for the suggestion and the link, i will download the SP6 later, although i am now sure what the problem is, and it's not anyhow SP related.

    Quote Originally Posted by Merri
    This made me laugh, just the other day I read "programmer's famous last words" and this line here is word-to-word perfect on the list
    I totally agree with you. But not in this case. I mean this is a rather (up to some level) simple, or lets say not so complicated, code/program, that one can be sure that it has no problems, specially after fixing many many bugs in it, and after restructuring/rewriting it many times. It certainly had problems, and i changed almost the whole code many times before claiming that it has no problems, so... definitely not my last words, i've only been in this programming game for 2 years, so i'm just getting started.


    Anyway, i will post shortly again since i came to some rather interesting facts about this problem. Still conducting some tests now.
    "And Now I'm Lika Major Threat, Cause I Remind U Of The Things U Were Made To Forget!" - (2PAC)

    "Now They Label Me a Lunatic, Couldn't Care Less, Death or Success is What I Quest, Cause I'm Fearless!" - (2PAC)

    " There's a light at the end of every tunnel, just pray it's not a train!! "



    I am 100% addicted to Tupac. What about you?
    I am 24% addicted to Counterstrike. What about you?
    The #1 Tupac Fans Web Site | The Official Tupac Web Site

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