Maya wrote: Tue Oct 31, 2023 9:20 am
Is there another function in PureBasic that find in Memory, more than One Hex Byte?
Welcome to the forum Maya. If speed is the concern, as you say you want to avoid looping, the below may be faster. It avoids using Peek and advances through the memory by a unicode character at a time. This example completes in 1ms and that's with the debugger on. It assumes the contents are stored as Unicode, since that is PureBasic's default for strings.
Code: Select all
OpenConsole()
Define str.s = "This serves as an example of memory contents"
Define *strpointer.Unicode
*strpointer = @str
While *strpointer\u ; Strings being null terminated, will end here
Print(RSet(Hex(*strpointer\u), 2, "0" )) ; Convert value to hex
*strpointer + SizeOf(Unicode) ; Advance the pointer
Wend
Input()
ASCII version — If you are instead reading ASCII data, therefore single bytes, this would need to be modified, as per this second example.
Code: Select all
OpenConsole()
Define *str = Ascii("This serves as an example of memory contents") ; Store string as ASCII, *str is pointer to contents
Define *strpointer.Ascii
*strpointer = *str
While *strpointer\a ; Strings being null terminated, will end here
Print(RSet(Hex(*strpointer\a), 2, "0" )) ; Convert value to hex
*strpointer + SizeOf(ascii) ; Advance the pointer by 1 byte (ASCII)
Wend
Input()