Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21246

Initialize and allocate memory for String through pointer and/or memory routines

$
0
0
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:

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

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:
Code:

MyRoutine = String$(lBufLen \ 2, 0)
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.

Viewing all articles
Browse latest Browse all 21246

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>