Marook-Online
* 06.Feb.2012, 15:10 UTC+1
Welcome, Guest. Please login or register.
Username:
Password:

News: Back again Wink
Main Menu
  Navigation
   Downloads
     Tools
     Music Discs
     SMF Mods
     Trainer & Patches
     EgoShare Uploader
   Guestbook
   NoPaste
   User Map
   Gallery
  
   Malware Scan
   Hacker Blacklist
   Find Abusemail
Top Downloads
Support Me !
Help me by donating a small amount!



Advanced search

Google


Pages: [1]   Go Down
0 Members and 1 Guest are viewing this topic. Topic Tools  
Read
19-Dec-2007 03:17
Marook
Administrator
*****
Offline Offline

Joined: 01-Jan-2005
Posts: 224


Most of the people use string everywhere in their code. Actually when doing string concatenation, do you know what exactly your doing? It has a big drawback mainly in concatenation which can be overcome by StringBuilder. It will give vast improvement in performance when you use concatenation of string over String.

First we will look at what happens when you concatenate two strings

Code:
Dim tString As String = String.Empty

For i As Integer = 1 To 10000
    tString += "Test"
Next

Here we're concatenating the string "Test" 10000 times to the string tString. This is a performance leak because we're assigning 9999 new strings!

If we can have something which are be defined only once and add all the strings into it, what can you say about the performance. That's what StringBuilder is doing.

Code:
Dim sb As New System.Text.StringBuilder

For i As Integer = 1 To nCount.Value
    sb.Append("Test")
Next

This code will do the same as the code above but faster. If you just want to concatenate a few strings together you can choose your preferred mode, but if you want with 1000's and more you really should work with the stringbuilder. Try the attached example-project to see the difference.
Logged
 

Pages: [1]   Go Up
Jump to:  

Theme by webtechnica.net

MHD v2.1 © 2oo8 by Marook
32116 hacking attempts defended!