|
-
Mar 18th, 2005, 11:07 AM
#1
Thread Starter
Hyperactive Member
Re: Hopeless: memory not being released
 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
-
Mar 18th, 2005, 01:41 PM
#2
Re: Hopeless: memory not being released
TupacShakur, Are you sure you have the latest VB6.0 Service Pack (SP6) ?
-
Mar 18th, 2005, 02:00 PM
#3
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.
-
Mar 18th, 2005, 03:57 PM
#4
Thread Starter
Hyperactive Member
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
-
Mar 18th, 2005, 05:07 PM
#5
Re: Hopeless: memory not being released
I have faith in merri. I gave him the link to this thread. He can fix it.
-
Mar 18th, 2005, 05:56 PM
#6
Re: Hopeless: memory not being released
 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
-
Mar 18th, 2005, 06:48 PM
#7
Re: Hopeless: memory not being released
 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:
Option Explicit
Const Filename = "E:\tempfile"
Const vbMEGABYTE As Long = 2097152
Dim Quit As Boolean
Private Sub Command1_Click()
Dim Filesize As Long, Counter As Long, A As Long
Dim ReadBuffer() As Byte, TempBuffer() As Byte, EndPos As Long
ReDim ReadBuffer(vbMEGABYTE - 1)
Filesize = FileLen(Filename)
Open Filename For Binary Access Read As #1
Do While (Filesize - Seek(1)) \ vbMEGABYTE
Counter = Counter + 1
Open Filename & "_" & Format$(Counter, "00") & ".sql" For Binary Access Write As #2
If Not ((Not TempBuffer) = True) Then Put #2, , TempBuffer
Get #1, , ReadBuffer
EndPos = InBArrRev(ReadBuffer, "INSERT INTO ")
ReDim Preserve TempBuffer(vbMEGABYTE - EndPos - 1)
For A = EndPos To vbMEGABYTE - 1
TempBuffer(A - EndPos) = ReadBuffer(A)
Next A
ReDim Preserve ReadBuffer(EndPos - 1)
Put #2, , ReadBuffer
ReDim Preserve ReadBuffer(vbMEGABYTE - 1)
Close #2
Command1.Caption = Format$((Seek(1) / Filesize * 100), "0.00") & " %"
DoEvents
If Quit = True Then Close #1: Unload Me
Loop
Counter = Counter + 1
ReDim Preserve ReadBuffer(Filesize - Seek(1) - 1)
Get #1, , ReadBuffer
Open Filename & "_" & Format$(Counter, "00") & ".sql" For Binary Access Write As #2
Put #2, , TempBuffer
Put #2, , ReadBuffer
Close #2
Close #1
Command1.Caption = "Done!"
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Quit = True
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.
-
Mar 19th, 2005, 02:52 PM
#8
Thread Starter
Hyperactive Member
Re: Hopeless: memory not being released
 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.
 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|