C++ doesn’t have a
foreach keyword, but it does have an equivalent in “range
for loops”. Today we’ll implement support for them so we can easily loop over arrays and types implementing
Posts Tagged array
C++ doesn’t have a
The series continues by adding support for a major feature: arrays. These are used very frequently throughout the Unity and .NET APIs and the lack of support for them has been a big missing piece of the puzzle for most games. The GitHub project has been updated to support single- and multi-dimensional arrays. Read on to learn how this support was implemented!
Every time I see
for (var i = 0; i < array.Length; ++i) I wonder if accessing that
Length property is slow. Should I cache it? It’s comforting to know that
for (int i = 0, len = array.Length; i < len; ++i) is only dealing with local variables except on the first loop. Local variables must be faster, right? Likewise, I wonder the same thing about
List<T>.Count. I finally got around to running a test to see if caching these length properties makes any performance difference. The answers might surprise you!
We’re nearing the end of the series to build a no-garbage replacement for
System.Linq. Today we tackle functions that work on already-sorted ranges and functions that work on ranges that are in heap order. These include common set operations like “union” and “intersection”. Read on to see how to use them and for the updated library that you can use to eliminate your garbage creation!
Back from a brief break, we pick up this week by finishing up the “modifying sequence operations” with some gems like
RandomShuffle and go through the “partitions” category with functions like
IsPartitioned. These are all solid algorithms with a lot of potential uses, so read on to see how to use them with iterators and for the source code that implements them!
Last week’s article introduced the concept of iterators as an alternative to the GC-heavy
IEnumerable. Today’s article expands the iterator library to include a bunch of more functions to make it useful. Think of these like the extension functions in
IndexOf, etc. These have all been tailored to iterators and none of them will create any garbage whatsoever.