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!
Posts Tagged enumerable
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!
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!