Results 1 to 2 of 2

Thread: Fast string appending in VB6

  1. #1

    Thread Starter
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359

    Fast string appending in VB6

    I've had this code lying around, so thought I would post it here.
    It is ( well, should be ) a lot faster than VB's internal string appending & operator.

    VB Code:
    1. Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
    2.  
    3. Private Sub appendToString(ByRef strBuff As String, ByVal strStringToAppend As String)
    4.     CopyMemory ByVal StrPtr(strBuff) + LenB(strBuff), ByVal StrPtr(strStringToAppend), LenB(strStringToAppend)
    5. End Sub
    6.  
    7. '' Sample Usage
    8. ''
    9. Private Sub Form_Load()
    10.     Dim i As Long, x As String: x = "a"
    11.     For i = 0 To 10000
    12.         appendToString x, CStr(i)
    13.     Next
    14.     MsgBox x
    15. End Sub
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Fast string appending in VB6

    And the memory is allocated where....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width