Posts Tagged enumerable

BitArray32 and BitArray64

Tags: , , , ,

C# already has two bit array types, but both are lacking. BitArray is a class so it requires heap allocation and GC. BitVector32 is a struct, but it’s usage is bizzare, it’s implemented inefficiently, it’s not enumerable, and there’s no 64-bit version. Today we’ll create a new, simple type to remedy these issues and add a new tool to our toolbox!

Read the rest of this article »

6 Comments

Iterators vs. Callbacks: Performance and Garbage

Tags: , , , , , , ,

Iterator functions and their ability to yield return values then continue on really come in handy for a variety of situations. Unfortunately, they come with some pretty serious performance and garbage creation drawbacks. So today’s article explores alternatives in various forms of callbacks: delegates, interfaces, and classes. Can they perform better than iterator functions? Can they avoid garbage creation? Read on to find out!

Read the rest of this article »

2 Comments

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 »

1 Comment