Thursday, August 26, 2010

Performance consideration using collection .Net framework

 

.Net framework is loaded with good amount of collection to make programming as easier, when we are developing small application it is ok if we don’t consider which

Programming practice is batter then other. But if we are working on any application having enterprise customers we must have to think about which programming element is batter over other. Here I have tried to make some flash over this.

 

1) Array:

·         Use strongly typed array if you don’t won’t much operations like searching and sorting.

·         Strongly Arrays gives best performance because they avoids boxing and unboxing.

2) Iteration:

·         Index based iteration will be efficient then enumerating (for each). Use loops for very big size collections.

3) Collections:

·         Prefer Array over Collection for storing Value types, this will avoid boxing and unboxing.

·         Use strongly typed collection, Use StringCollection for storing string instead of ArrayList.

·         Use binary search method while searching large size ArrayList.

·         Store small amount of data in ListDictionary instead of Hashtable.

·         Use StringDictionary for storing strings.

·         Avoid using SortedList if you are performing add/update operation frequently, use ArrayList instead.

·         If you are Using ArrayList declare it with approximate possible length, this will save memory, remember that doing this you will not lost variable length feature of ArrayList.(e.g. Use ArrayList arrList = new ArrayList(4);)

 

Any inputs will always be accepted.

 

Thanks,

Haresh Dhameliya.