Re: Function horribly slow
- From: "Karl E. Peterson" <karl@xxxxxxxx>
- Date: Tue, 7 Oct 2008 18:23:49 -0700
Patrick Weidener wrote:
Can anyone tell me why this function is so horribly slow (on some PCs)???
The buffer's awfully small by today's standards. I'd use 4Mb rather than 4Kb, for
example. No need to recreate it on each loop, either.
Also, you're gonna get *clobbered* on performance by, and risking data corruption
due to, UniMess -- you're doing binary file i/o with Strings! Nasty. Use Byte
arrays instead.
--
..NET: It's About Trust!
http://vfred.mvps.org
Public Function FileForceCopy(ByVal uSource As String, ByVal
uDestination As String) As Boolean
On Error GoTo ErrHandler
Dim lSourceLen&
Dim iSF%
Dim iDF%
Dim sChunk As String
Dim iBytesToGet%
Dim lBytesCopied&
Debug.Print uSource
Debug.Assert FileExists(uSource)
'/* Get source file length */
lSourceLen = FileLen(uSource)
'/* Open both files */
iSF = FreeFile()
'/* We MUST open a file after calling FreeFile(), else the next
FreeFile will be the same number */
Open uSource For Binary Shared As #iSF
'/* Only know we can call the next FreeFile() */
iDF = FreeFile()
Debug.Print uDestination
TryKill uDestination
If FileExists(uDestination) Then
Debug.Print "Source: " & uSource
Debug.Print "Destination: " & uDestination
Debug.Assert False
Exit Function
End If
Debug.Print uDestination
Open uDestination For Binary As #iDF
'How many bytes to get each time
iBytesToGet = 4096 '4kb
lBytesCopied = 0
'Keep copying until finishing all bytes
Do While lBytesCopied < lSourceLen
'Check how many bytes left
If iBytesToGet < (lSourceLen - lBytesCopied) Then
'Copy 4 KBytes
sChunk = Space(iBytesToGet)
Get #iSF, , sChunk
Else
'Copy the rest
sChunk = Space(lSourceLen - lBytesCopied)
Get #iSF, , sChunk
End If
lBytesCopied = lBytesCopied + Len(sChunk)
'Put data in destination file
Put #iDF, , sChunk
Loop
Close #iSF
Close #iDF
FileForceCopy = True
Exit Function
ErrHandler:
Debug.Print Err.Description
Debug.Assert FileExists(uSource)
'Debug.Print Len(uSource)
Debug.Print uDestination
Debug.Print uSource
Debug.Assert False
Call WriteLog("#FileForceCopy: " & Err.Description & ", err.number: " &
Err.Number & ", Params: '" & "" & "'")
End Function
.
- Follow-Ups:
- Re: Function horribly slow
- From: Patrick Weidener
- Re: Function horribly slow
- References:
- Function horribly slow
- From: Patrick Weidener
- Function horribly slow
- Prev by Date: vb6.0 create recurrence schedule
- Next by Date: Re: vb6.0 udp multicast problem
- Previous by thread: Re: Function horribly slow
- Next by thread: Re: Function horribly slow
- Index(es):
Relevant Pages
|
Loading