Supercharge your peek_string()

new topic     » topic index » view thread      » older message » newer message

Platform: Windows


No more hunting character by character
through memory for that notorious
zero string terminatorsmile

This new way of peek'ing a zstring is typically
at least 5 times faster then the old way, and its
only one line of code smile

--first link to this windows function any way you see fit:

xlstrlen=link_c_func(kernel32,"lstrlen",{C_POINTER},C_INT)


--then the new Euphoria function becomes:

function peek_zstring(atom lpzString)
  return peek({lpzString,c_func(xlstrlen,{lpzString})})
end function

That's it!

I've named it "peek_zstring" to distinguish it from the old
function "peek_string", but more importantly to draw attention
to the importance of using it ONLY on zero terminated strings.
The speed increase should be REALLY drastic for very long
strings.


--typical usage:

atom lpFilename
sequence teststring

lpFilename=allocate_string("c:\\program files\\thisdir\\filename.txt")
teststring=peek_zstring(lpFilename)
printf(1,"%s\n",{teststring})
free(lpFilename)


On this particular string it benchmarked about 5 times faster
then a minimum form of the old peek_string().

Good luck with it!
--Al

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu