|
-
Mar 18th, 2005, 10:37 AM
#1
Re: Hopeless: memory not being released
One other thing to try would be to use a fixed size array. I'd bet that VB is leaking memory from the array allocations. Dynamic arrays have additional overhead in terms of memory allocations, and the redimensions may be the problem. BTW, the preserve keyword actually uses double the amount of memory because it actually copies the entire array into a new array in memory and then (in theory ) deallocates the previous one. If you think about it, it has to work this way to ensure that the new array gets a contiguous region in memory. There is no way of knowing if the additional addresses above the original allocation are free, so it plays it safe and just makes it bigger. You should be OK if you just avoid making memory operations inside your loop.
See if you can get something like this to work. I collapsed your loop a little bit.
VB Code:
Dim FullBuffer(BUFFER - 1) As Byte, j As Integer 'additional dims. Assumes BUFFER is a const.
hFile = FreeFile
Open Filename For Binary Access Read As #hFile
For i = 1 To chunkNum
'tells us how much is still to be read...
If (i = chunkNum) Then
tempChunkSize = lastChunkSize
Else
tempChunkSize = realChunkSize
End If
'get new filename
sliceFileName = desPath & slicePrefix & Format$(i, formatStr) & "." & fileExt
aFile = FreeFile
'open file for write
Open sliceFileName For Binary Access Write As #aFile
Do While (tempChunkSize > 0)
'read and write
Get #hFile, , FullBuffer
If tempChunkSize >= BUFFER Then
Put #aFile, , FullBuffer 'write the whole thing.
Else
For j = 1 To tempChunkSize 'write each byte individually - only doing
Put #aFile, , FullBuffer(j) 'this once per file, so the overhead isn't
Next j 'that much.
End If
'progress forward
tempChunkSize = tempChunkSize - BUFFER
PB1.value = PB1.value + 1
'Erase FullBuffer 'try uncommenting this as a next step.
Loop
Close #aFile
'let windows refresh etc.
DoEvents
Next i
Close #hFile
-
Mar 18th, 2005, 11:03 AM
#2
Thread Starter
Hyperactive Member
Re: Hopeless: memory not being released
 Originally Posted by Comintern
One other thing to try would be to use a fixed size array.
[...]
You should be OK if you just avoid making memory operations inside your loop.
People, forgive me for using this statement too much: ALREADY TRIED THAT ... It seems this is truely a hopeless case.
 Originally Posted by Comintern
I'd bet that VB is leaking memory from the array allocations.
I'd bet VB is leaking memory from all over .
 Originally Posted by Comintern
I collapsed your loop a little bit.
I tried this approach, but, as i expected, same problem is occuring. Thanks for ur help guys.
"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
|