下列二種摘錄自網路,請問method 1用block_size先行運算,method 2
則無,二種方法之間,速度有何差異?
Method 1:
Private Const BLOCK_SIZE = 10000
...
file_num = FreeFile
Open dlgPicture.FileName For Binary Access Read As #file_num
file_length = LOF(file_num)
If file_length > 0 Then
num_blocks = file_length / BLOCK_SIZE
left_over = file_length Mod BLOCK_SIZE
Set rs = New ADODB.Recordset
rs.CursorType = adOpenKeyset
rs.LockType = adLockOptimistic
rs.Open "Select Name, Picture, FileLength FROM People", m_DBConn
rs.AddNew
rs!Name = person_name
rs!FileLength = file_length
ReDim bytes(BLOCK_SIZE)
For block_num = 1 To num_blocks
Get #file_num, , bytes()
rs!Picture.AppendChunk bytes()
Next block_num
If left_over > 0 Then
ReDim bytes(left_over)
Get #file_num, , bytes()
rs!Picture.AppendChunk bytes()
End If
rs.Update
Close #file_num
'
Method 2:
'read file contents to byte array
iFileNum = FreeFile
Open sTempFile For Binary Access Read As #iFileNum
lFileLength = LOF(iFileNum)
ReDim abBytes(lFileLength)
Get #iFileNum, , abBytes()
'put byte array contents into db field
rs.Fields(FieldName).AppendChunk abBytes()
Close #iFileNum