Hello,
I wrote a routine that parses strings passed to it, and which will be looped millions of times. I refined it to the point that it's running pretty fast, but not quite where I want it. I can trace the bottleneck (or a big part of it) to a String function call. Here is some code that explains what I mean:
As you can see, I am making use of pointers obtained through StrPtr and the CopyMemory call to efficiently search/parse the string in "byte" mode as is in memory without the overhead of additional conversions or slow routines. But when it's time to take a chunk of memory bytes and put them into the return string, I can't seem to find an alternative to this call:
I tried dabbling with the GetProcessHeap and HeapAlloc API calls, but couldn't figure out how to initialize and/or allocate memory for the return string more efficiently through pointers.
Can this be done, or does it even make a difference?
Needing some help... Thanks.
I wrote a routine that parses strings passed to it, and which will be looped millions of times. I refined it to the point that it's running pretty fast, but not quite where I want it. I can trace the bottleneck (or a big part of it) to a String function call. Here is some code that explains what I mean:
Code:
Private Function MyRoutine(Str As String) As String
Dim lPtr As Long, lBufLen As Long
lPtr = StrPtr(Str)
'yada
'yada
'yada
MyRoutine = String$(lBufLen \ 2, 0) 'Slowing things down a bit
CopyMemory ByVal StrPtr(MyRoutine), ByVal lPtr, lBufLen
End Function
Code:
MyRoutine = String$(lBufLen \ 2, 0)
Can this be done, or does it even make a difference?
Needing some help... Thanks.