Posts Tagged list

SafeList 2.0

Tags: , , , ,

The first version of SafeList tried to address a common problem: inserting and removing elements into a List<T> while you loop over it. It had a lot of problems though and ended up being pretty much useless. Today’s article presents SafeList 2.0, a radically-improved version that really solves the problem so you can actually use it as a drop-in replacement for List<T>. Read on for the details, the source code, and even the unit tests that prove it handles all the nasty corner cases for you!

Read the rest of this article »

No Comments

For vs. Foreach

Tags: , , , , ,

foreach loops are really convenient, but are for loops faster? It’s a simple question, but one that has really wide implications in almost any codebase. Today’s article tests them out to see which is faster for looping over arrays and Lists. Read on to see which is quicker!

Read the rest of this article »

12 Comments

Linked Lists Are Slow

Tags: , , ,

Contrary to what you may have learned in a data structures class, linked lists are virtually always slower than just using arrays. The same goes for array wrapper classes like List. Today’s article discusses why this is the case and tests it out with a C# Unity app to make sure that the real world validates the theory.

Read the rest of this article »

2 Comments

Optimizing Arrays and Lists

Tags: , , , ,

Last week’s article compared the performance of arrays with List<T> and found List lacking. This week we’ll optimize both List and array to maximize performance regardless of which you choose to use.

Read the rest of this article »

1 Comment

Array vs. List Performance

Tags: , ,

System.Collections.List<T> is used everywhere in C# code. Except for very special cases, it’s the replacement for arrays, linked lists, queues, and most other one-dimensional data structures. This is because it has all kinds of extra functionality, including the ability to grow in size on-demand. Today’s article wonders about how much performance is lost to gain this convenience and tests the List<T> class against the lowly C# array: T[]. How much performance are you giving up with List and why is that happening? Read on to find out!

Read the rest of this article »

7 Comments

SafeList: A Class To Eliminate Foreach Errors

Tags: , , ,

Today’s article shows a class that helps clean up your foreach loops when you want to call Add() or Remove() on the List you’re looping over. Normally you’d get an exception, but today’s class works around that problem so your code is less error-prone and easier to read. It also discusses some workarounds you can use even if you don’t use SafeList. Read on to learn how to make your foreach loops less error-prone! UPDATE: SafeList 2.0 is out!

Read the rest of this article »

6 Comments