Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Optimized way to transfer from String to StringBuilder
Message
De
08/02/2014 18:34:25
 
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01593079
Message ID:
01593760
Vues:
36
>If you're running in a loop the entire string routine should probably be going into StringBuilder(). String concatenation in .NET is expensive because every string - dynamic or static - requires an object reference. While they are short lived they use memory and use the heap and .NET has to keep track of it and clear out those references. So if you're doing under 10 concats total there's no need to use a StringBuilder. Anything more StringBuilder starts making sense in addition to often being an easier interface to output string data.

Correct, but in here, even if it goes in the loop, it's mostly for verification and ajust very rarely some words. It is not a concatenation. As I have adjusted the code to avoid passing a long string in there, basically just the average daily SQL command, this is ok as is. It is just that for a while, I was testing a new approach and this was a very big SQL command. So, while checking in there, I found out it was taking 0.7 extra second to parse and verify. But, in both ways, they were pretty much the same. The string was enormously big, so it would have taken pretty much the same amount of time in both approaches. But, that is already old code. The actual code is the one that was there before and the string length is controlled. String does the job pretty good.

Thanks
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform