AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

A faster method than DllCall("RtlFillMemory", ?

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Rabiator



Joined: 17 Apr 2005
Posts: 264
Location: Sauerland

PostPosted: Tue May 01, 2007 12:37 pm    Post subject: A faster method than DllCall("RtlFillMemory", ? Reply with quote

Is there a faster way than
Code:
DllCall("RtlFillMemory", UInt, Pointer, Int, 1, UChar, Byte)
to manipulate a byte in memory? On my computer (1800 MHz) this command takes 22 µs, reading a byte with
Code:
Byte := *Pointer
takes about 1 µs. I tried
Code:
*Pointer := Byte
(like in C), but that doesn't work, Very Happy. Apparently there is some continuation mechanism in effect.

With small memory blocks the speed will suffice, but I use it to manipulate binary files with a size of several MBs.

__________________________________________
Created with BBCodeWriter 7.0 - the one and only Very Happy
Back to top
View user's profile Send private message
PhiLho



Joined: 27 Dec 2005
Posts: 6721
Location: France (near Paris)

PostPosted: Tue May 01, 2007 4:43 pm    Post subject: Reply with quote

I believe I posted this in the Wish List... At least for symmetry, and even more for convenience.
Of course, this operation should work only within a memory allocated/owned by AutoHotkey (with VarSetCapacity or string concatenation, for example), for security reasons (too easy to crash a script otherwise).
_________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")
Back to top
View user's profile Send private message Visit poster's website
Sean



Joined: 12 Feb 2007
Posts: 1247

PostPosted: Wed May 02, 2007 2:39 am    Post subject: Re: A faster method than DllCall("RtlFillMemory", Reply with quote

Rabiator wrote:
Code:
*Pointer := Byte

I like it!
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 3942
Location: Pittsburgh

PostPosted: Wed May 02, 2007 3:02 am    Post subject: Reply with quote

Code:
DllCall("RtlFillMemory", UInt, Pointer, Int, 1, UChar, Byte)
is slow, because AHK needs to convert 3 strings (variables) to binary, and look up a function, named by another string. If you have at least 4 bytes to write, (Win2K+)
Code:
DllCall("ntdll\RtlFillMemoryUlong", UInt, Pointer, UInt,4, UInt,word)
takes about the same time, but writes 4 bytes. If even larger memory areas have to be written many times, you can fill a buffer once, and copy it over to the desired place. Of course, a built in solution will be better.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group