Handling Internal Errors

Tags: , , ,

Some errors can be handled and some cannot. Nevertheless, it’s extremely common to see codebases chock-full of ineffective error handling for these unrecoverable issues. The result is a lot of extra code to write, maintain, and test that often serves to make debugging harder. Today’s article shows you how to make debugging internal errors so much easier by effectively writing code to handle them.

Read the rest of this article »

No Comments

Supporting ParallelFor Jobs in Ranged Native Collections

Tags: , ,

Native collections are funny things. On one hand they’re structs, which are supposed to be value types that get copied on assignment. On the other hand, they act like reference types because they contain a hidden pointer internally. This can make using and implementing them difficult to understand, especially in the context of a ParallelFor job. Today we’ll examine more closely how to properly support ParallelFor jobs, especially with ranged containers like NativeList<T>.

Read the rest of this article »

No Comments

NativeChunkedList<T>: Part 2

Tags: , ,

Last week we looked at a new native collection type: NativeChunkedList<T>. This type saved us a lot of memory and gave us a faster way to dynamically grow an array. Unfortunately, iterating over it was quite a lot slower. Today we’ll speed it up for both IJob and IJobParallelFor. In doing so, we’ll learn more about how to create custom Unity job types and about how IEnumerable and IEnumerator work.

Read the rest of this article »

No Comments

NativeChunkedList<T>

Tags: , ,

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 »

2 Comments

Next-Level Code Generation

Tags: ,

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 »

4 Comments

DIY Iterators and Coroutines

Tags: , , ,

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 »

No Comments

NotNull and Owner

Tags: , ,

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 »

2 Comments

NativeIntPtr and NativeLongPtr: Part 2

Tags: , , , ,

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 »

6 Comments

NativeIntPtr and NativeLongPtr

Tags: , ,

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 »

4 Comments

The Effects of Useless Code

Tags: , , , ,

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 »

No Comments