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
- List<string> list = new List<string>();
- Console.Write(list.Capacity);
- // This would output '0'
-
- list.Add("something");
- Console.Write(list.Capacity);
- // This would output '4'
-
- for (int i = 0; i < 4; i++)
- {
- list.Add(i.ToString());
- }
- // List contains 5 items
-
- Console.Write(list.Capacity);
- // This would output '8'
Now this can be gracefully handled by providing the capacity in the constructor as shown below:
Code Snippet
- List<string> newList = new List<string>();
- newList.Capacity = 5;
- newList.Add("junk");
- Console.Write(newList.Capacity);
- // This would output '5'
068de470-5362-4321-8bea-e66ea9a91b3c|4|3.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:

1f0be1e1-faed-4684-bb3f-354e98dd9234|8|4.0