0

我正在处理一个在循环内部使用二进制文件并读取其字节连续的脚本,(也能够在文件内来回走动(savepos)(setpos))

但我不知道我需要使用什么方法所以它对性能还不错

我的第一次尝试是将 FileRead 与 FileHandle 一起使用,但遗憾的是,随着程序的进展和从文件中进一步读取,这使得程序的速度变慢(对于 10MB 文件,程序在 30 分钟后完成)

$File = FileOpen($Path, 16)
$tTimer = TimerInit()
$ndx = 4
for $i=0 to 100000
    $test = FileRead($File, $ndx)
    $ndx += 4
    ConsoleWrite($test & @CRLF)
Next
ConsoleWrite(TimerDiff($ttimer) &" Sekunden"& @CRLF)

所以我尝试先将整个文件读入一个变量,然后用 BinaryMid 从中读取二进制文件
但是这种方法更慢......

$File = FileOpen($Path, 16)
$Readfilee = FileRead($File)
$tTimer = TimerInit()
$ndx = 4
for $i=0 to 100000
    $test = _BinaryRead(4)
    ConsoleWrite($test & @CRLF)
Next
ConsoleWrite(round(TimerDiff($ttimer) /1000,2) &" Sekunden"& @CRLF)

Func _BinaryRead($iCount)
  $ndx += $iCount
  Return BinaryMid($Readfilee, $GNOW - $iCount, $iCount)
EndFunc

所以我想知道我能做些什么来尽可能快地读取 Bin 文件?

抱歉,如果这不是一个好问题,我是 autoit 新手

4

1 回答 1

0

您无需逐字节读取文件,该函数FileRead()只需一步即可为您完成所有工作,您可以使用以下内容:

$hFile = FileOpen($Path, $FO_BINARY)
$tTimer = TimerInit()
$bFileContent = FileRead($hFile)
FileClose($hFile)
; Now you can use $bFileContent as you want.
ConsoleWrite(TimerDiff($ttimer) &" Sekunden"& @CRLF)
于 2021-07-12T19:13:03.203 回答