|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Intern Strings - am I using them right? Please help!I have heard a lot about intern string - so I wanted to use them to increas e speed of processing. I have a hastable that I am using to parse a string of the form: wordA wordB wordC wordD etc etc I want to de-duplicate the string - that is, remove any repeated words so that only 1 occurance of the word exists. Its working fine - takes about 25 mins to do all the strings that I have for it so I intriduced the line: String.Intern(s) in an effort in incrase spped of processing. My question is though - am I using intern string correctly? Am I msiing anything or using them incorrectly? Any comments/suggestions/code-samples much appreciated. Al. ******** CODE AS FOLLOWS ******** Public Function DeDuplicate(ByVal str As String) As String Dim ht As New Hashtable Dim s As String For Each s In str.Split(" "c) Try String.Intern(s) If Not ht.ContainsKey(s) Then ht.Add(s, s) End If Catch ex As Exception Debug.WriteLine(ex.ToString) End Try Next 'Convert hashtable -> string Dim deDupStr As String Dim Item As DictionaryEntry For Each Item In ht 'String.Intern(deDupStr) 'Trace.WriteLine(Item.Value) deDupStr += Item.Value.ToString + " " Next Return deDupStr.Trim() End Function > I have heard a lot about intern string - so I wanted to use them to I think you could gain more by using a StringBuilder when recreating>increas e speed of processing. the stirng instead of the += operator. >String.Intern(s) Why do you think interning ths string would make your processing> > in an effort in incrase spped of processing. My question is though - >am I using intern string correctly? faster? Did you see any performance increase? Mattias -- Mattias Sjögren [C# MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com Please reply only to the newsgroup. Mattias Sjögren wrote:
> > I have heard a lot about intern string - so I wanted to use them to Thanks. I'll try this and see does it imporve speed of processing.> >increas e speed of processing. > > I think you could gain more by using a StringBuilder when recreating > the stirng instead of the += operator. > >String.Intern(s) No - afraid not. Nothing amazing to make me sit up.> > > > in an effort in incrase spped of processing. My question is though - > >am I using intern string correctly? > > Why do you think interning ths string would make your processing > faster? Did you see any performance increase? Hope I used them right... Thank for your help Mattias. A.
AMD/Dual-Core/64 bit: influence on compiled files? - Clients?
Can I hide base class properties in a derived class? change IFRAME src Multithreading Using pulldownlist in datagridview .. can it be done! Inserting text at the beginning of an existing text file .NET 2.0 question ? executing a .dll? Reading from the COM Port stopping a process |
|||||||||||||||||||||||