Posted by Nazar Rizvi on 8/24/2010 10:24 AM | Comments (0)

People who deal with performance issues and high-end systems already know about the effective ways to use List<t> from System.Collections class. The msdn documentation for List<t> is available here: List<t> msdn Documentation 

Usually this will never be an issue unless you are dealing with high-performance applications or mobile applications. Whenever a new List<T> is created, the constructed capacity is 0. This utilizes minimal memory. But as you keep on adding items to the list the capacity grows exponentially i.e. 4, 8, 16, 32, 64 …

Run this piece of code to verify yourself.

Code Snippet
  1. List<string> list = new List<string>();
  2.             Console.Write(list.Capacity);
  3.             // This would output '0'
  4.  
  5.             list.Add("something");
  6.             Console.Write(list.Capacity);
  7.             // This would output '4'
  8.  
  9.             for (int i = 0; i < 4; i++)
  10.             {
  11.                 list.Add(i.ToString());
  12.             }
  13.             // List contains 5 items
  14.  
  15.             Console.Write(list.Capacity);
  16.             // This would output '8'

 

Now this can be gracefully handled by providing the capacity in the constructor as shown below:

Code Snippet
  1. List<string> newList = new List<string>();
  2.             newList.Capacity = 5;
  3.             newList.Add("junk");
  4.             Console.Write(newList.Capacity);
  5.             // This would output '5'
Posted by Nazar Rizvi on 8/8/2010 6:00 PM | Comments (0)

I have been using CoolIris for websites in order to maintain my photo gallery. Initially editing the XML manually using TextPad was cool but after few occasions it ended up being a pain to manage.  Below is a basic web form I created to upload and edit RSS feed to work with the CoolIris control I use. You can use the attached piece of code to work with your web server (Modify it as needed)

 SourceCode: