Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

Use CopyMemory api for performance.
[ All Languages » VB »  Memory]

Total Hit ( 4622)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


This article will demonstrate that how CopyMemory can boost the performance of for some simple operations (e.g string append.). Here we will banchmark VB Mid function vs CopyMemory Api.

Click here to copy the following block
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long)
Private Declare Function GetTickCount Lib "kernel32" () As Long
Private Sub Form_Load()
  Dim sSave As String, Cnt As Long, T As Long, Pos As Long, Length As Long
  Const mStr = "Hello "
  Length = Len(mStr)
  sSave = Space(15000 * Length) 'make buffer for justified comparison
  'Get the current tickcount
  T = GetTickCount
  Pos = 1
  sSave = Space(15000 * Length) 'Create Buffer
  For Cnt = 1 To 15000
   'Copy string into buffer using vb Mid function
   Mid(sSave, Pos, Length) = mStr
   Pos = Pos + Length
  Next Cnt
  'Show the results
  MsgBox "It took Visual basic" + Str$(GetTickCount - T) + " msecs. to add 15000 times a string to itself."
  'Get the current tickcount
  T = GetTickCount
  Pos = 0
  sSave = Space(15000 * Length) 'Create Buffer
  For Cnt = 1 To 15000
    'Copy string into buffer using CopyMemory API
    CopyMemory ByVal StrPtr(sSave) + Pos, ByVal StrPtr(mStr), LenB(mStr)
    Pos = Pos + LenB(mStr)
  Next Cnt
  'see the difference in performance
  MsgBox "It took CopyMemory" + Str$(GetTickCount - T) + " msecs. to add 15000 times a string to itself."
End Sub


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.