Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

What are potential performance issues when using BCL collections?

0
Posted

What are potential performance issues when using BCL collections?

0

The most common performance problems with using BCL collections include: Boxing and unboxing overhead for valuetypes. All standard BCL collections will box a valuetype when it’s added to collection, and unbox it when retrieving the value from the collection. Using iterators (the foreach statement) may be expensive, as it unrolls into a sequence of virtual calls through the IEnumerator interface (GetEnumerator(), get_Current(), and MoveNext()). For example foreach statement in the following benign piece of code: ArrayList al = new ArrayList(str_array); foreach (String s in al) { //do something } is compiled into: IL_002b: callvirt instance class [mscorlib]System.Collections.IEnumerator [mscorlib]System.Collections.ArrayList::GetEnumerator() IL_0030: stloc.s CS$5$0001 .try { IL_0032: br.s IL_004a IL_0034: ldloc.s CS$5$0001 IL_0036: callvirt instance object [mscorlib]System.Collections.IEnumerator::get_Current() IL_003b: castclass [mscorlib]System.String … IL_004a: ldloc.s CS$5$0001 IL_

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123