Monday, 15 July 2013

c# - How to iterate and remove elements from hashset most effective way -


Well, what I'm doing is but I'm surprised that this is the most effective way. I need to do this for RAM memory problems

  hashaseet < String & gt; Hslinks = new hashset & lt; String & gt; (); & Lt; String & gt; LstSortList = New list & lt; String & gt; (); // HashSet (true) with millions of records of filling {string srLastitem = ""; Foreign Language (different items in HSLIF) {srLastitem = item; break; } LstSortList.Add (srLastitem); HsLinks.Remove (srLastitem); Break (hsLinks.Count == 0); }  

C #. 4.5.2 wpf application

It looks like you have the item from hashtet If you are trying to move to list , then keep all going once and HashSet.Clear to use HashSet Empty:

  lstSortList.AddRange (hsLinks); HsLinks.Clear (); If you are worried about catching two copies of  context  * (as a suggestion of Wijora), then instead of single item instead of batches Can move:  P> 
  const b batch size = 1000; Var batch = new string [batch size]; Do {var batch index = 0; Forresh (various links in HSLinks. Tech (Batch Seiz)) {Batch [Batch Index] = Link; BatchIndex ++; } If (batch index and lieutenant; batch sequence) {batch = batch Take (Batch Index) .Oir (); } HsLinks.Exceptwith (batch); LstSortList.AddRange (batch); } While (HSLink.ne ());  

* Note: A reference size is 4 or 8 bytes (respectively at 32bit and 64bit)

). When you add strings (which are reference types on the net) you are not copying them in the list, only references (which are mostly negligible).


No comments:

Post a Comment