cheney Posted July 16, 2010 Share Posted July 16, 2010 (edited) Hi all: $nBytes = 1024 $hBuffer = DllStructCreate("ubyte buffer[" & $nBytes & "]") $pBuffer = DllStructGetPtr($hBuffer) . How to fill data pattern 0x55AA or any data pattern to $hBuffe not with "for"? What method is fast ?? call memset ?? Thanks for your answer Edited July 16, 2010 by cheney Link to comment Share on other sites More sharing options...
AndyG Posted July 16, 2010 Share Posted July 16, 2010 (edited) $nBytes = 1024 $hBuffer = DllStructCreate("ubyte buffer[" & $nBytes & "]") $pBuffer = DllStructGetPtr($hBuffer) $word = BinaryToString("0x55AA") $t = TimerInit() Do ;create string $word &= $word & $word ;grows fast.... Until StringLen($word) >= $nBytes $word = StringLeft($word, $nBytes) ;strip DllStructSetData($hBuffer, 1, $word) $m = TimerDiff($t) ;verify MsgBox(0, "Filled $hbuffer in " & $m & " ms", DllStructGetData($hBuffer, 1)) Edited July 16, 2010 by AndyG Link to comment Share on other sites More sharing options...
Spiff59 Posted July 16, 2010 Share Posted July 16, 2010 (edited) After flipping the high/low order of the bytes, this seems to be blazing fast: DllCall("ntdll.dll", "none", "RtlFillMemoryUlong", "ptr", $pBuffer, "int", 1024, "ulong", 0xAA55AA55) Edited July 16, 2010 by Spiff59 Link to comment Share on other sites More sharing options...
AndyG Posted July 16, 2010 Share Posted July 16, 2010 (edited) now it is academically....i ran 10000 loops with each solution.... dll-call 250 ms vs string 165 ms both equally fast.... But the bigger the struct, the faster the dll......i would prefer the dll Edited July 16, 2010 by AndyG Link to comment Share on other sites More sharing options...
Spiff59 Posted July 16, 2010 Share Posted July 16, 2010 (edited) I just went and looked on MSDN and found that call when I read the original post in here. But I don't think I'd regard 165 vs 250 as equally fast. I've never liked doing benchmarks via TimerInit/Diff, you can get some crazy results run-to-run, or weird fluctuations depending on the iterations. I just tried this: expandcollapse popup#include <Array.au3> $nBytes = 1024 $hBuffer = DllStructCreate("ubyte buffer[" & $nBytes & "]") $pBuffer = DllStructGetPtr($hBuffer) Global $loop, $Benchtable[5][4] For $loop = 0 to 4 $Benchtable[$loop][0] = 10 ^ ($loop + 1) Benchmark() Next _ArrayDisplay($Benchtable) Exit ;=============================================================================== Func Benchmark() $t = TimerInit() For $x = 1 to $Benchtable[$loop][0] $word = BinaryToString("0x55AA") ; needs to be inside loop to be reset when doing multiple iterations for benchmark testing Do ;create string $word &= $word & $word ;grows fast.... Until StringLen($word) >= $nBytes $word = StringLeft($word, $nBytes) ;strip ; DllStructSetData($hBuffer, 1, $word) Next $Benchtable[$loop][1] = TimerDiff($t) $t = TimerInit() For $x = 1 to $Benchtable[$loop][0] $word = BinaryToString("0x55AA") ; statement here only to make the benchmark comparison fair DllCall( "ntdll.dll", "none", "RtlFillMemoryUlong", "ptr", $pBuffer, "int", 1024, "ulong", 0xAA55AA55) Next $Benchtable[$loop][2] = TimerDiff($t) $t = TimerInit() $dll = DllOpen("ntdll.dll") ; faster when called multiple times with this statement For $x = 1 to $Benchtable[$loop][0] DllCall($dll, "none", "RtlFillMemoryUlong", "ptr", $pBuffer, "int", 1024, "ulong", 0xAA55AA55) Next DllClose($dll) $Benchtable[$loop][3] = TimerDiff($t) EndFunc I wasn't sure how to fairly handle resetting the $Word variable... I put a reset of it in the second loop, and tuned the third loop for speed typo Edited July 16, 2010 by Spiff59 Link to comment Share on other sites More sharing options...
cheney Posted July 17, 2010 Author Share Posted July 17, 2010 (edited) Thank you all for the answering Edited July 17, 2010 by cheney Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now