NativeChunkedList<T>

Today’s article is about a new native collection type: NativeChunkedList<T>. This type is great when you need a dynamically-resizable array that’s fast to add to and doesn’t waste a lot of memory. Read on to see how it’s implemented, see the performance report, and get the source code.

Read the rest of this article »

Next-Level Code Generation

About a year ago we saw how easy it is to use code generation to go beyond the limits of C# generics. The system we used simply replaced strings in a template file to generate a C# file. Today we’ll go way further and radically increase the power of the code generator by using some simple, off-the-shelf tools.

Read the rest of this article »

DIY Iterators and Coroutines

Iterators aren’t magic. We’ve seen the IL2CPP output for them and it’s not complex. It turns out we can just as easily implement our own iterators and gain some nice advantages along the way. Read on to learn how!

Read the rest of this article »

NotNull and Owner

The Guidelines Support Library is a small collection of utilities for C++. Today we’ll look at how two of them can make our C# code safer and cleaner.

Read the rest of this article »

NativeIntPtr and NativeLongPtr: Part 2

Last week’s article introduced two new native collection types: NativeIntPtr and NativeLongPtr. These were useful for both IJob and IJobParallelFor jobs, but performance was degraded in IJobParallelFor. Today we’ll remedy that, explore some more aspects of Unity’s native collection and job systems, and learn more about CPU caches along the way.

Read the rest of this article »

NativeIntPtr and NativeLongPtr

Today we’ll add two new types to the Native Collections suite: NativeIntPtr and NativeLongPtr. We’ll make them usable with both IJob and IJobParallelFor and explore some new features Unity’s native container system along the way.

Read the rest of this article »

The Effects of Useless Code

There are a lot of ways to write C# code that has no effect. One common way is to initialize class fields to their default values: public int Value = 0;. Today we’ll go over five types of useless code and see what effect it has on the actual machine code that the CPU executes. Do IL2CPP and the C++ compiler always do the right thing? Let’s find out!

Read the rest of this article »

The Maybe Monad

Monads sound fancy, but sometimes they’re actually really simple and useful. Today we’ll look at the Maybe monad, which is a low-overhead tool that’s extremely useful to prevent bugs.

Read the rest of this article »

C# Tasks vs. Unity Jobs

Two weeks ago we tested the performance of the async and await keywords plus the C# Task system against Unity’s new C# jobs system. This tested the usual combination of async and await with the Task system, but didn’t test the Task system directly against Unity’s C# jobs system. Today we’ll test that and, in so doing, see how to use the Task system without the async and await keywords.

Read the rest of this article »

How Async and Await Work

Last week’s article tested the performance of the async and await keywords plus the C# Task system against Unity’s new C# jobs system. This week we’ll go in depth with async and await to learn how they work, how they relate to the Task system, and how we can customize them for our own uses.

Read the rest of this article »