We code in C#, but that’s just a starting point. Our C# code is compiled to DLLs and then converted into C++ where it’s compiled again to machine code. The good news is that this isn’t a black box! I’ve recently been reading through the C++ code that IL2CPP outputs and learning quite a lot. Today’s article is about some of the surprises that I encountered and how you can change your C# code to avoid some nasty pitfalls.
Posts Tagged struct
Structs can be a great way to keep the garbage collector off your back and to use the CPU’s data cache more effectively. Not everything can be a struct though. At a minimum, you’ll need to use some Unity and .NET classes like
string. If your struct has any of these as fields, you can no longer use
sizeof(MyStruct). That really limits its usefulness, so a workaround is needed. Enter object handles: a simple way to represent any
object as a plain old
int which won’t break
sizeof. Read on to see how these work and some code you can easily drop into your project to start using them right away!
Most programmers write code for an abstract computer. The thing is- code runs on a real computer that works in a specific way. Even if your game is going to run on a wide range of devices, knowing some of the common features can speed up your code 10x or more. Today’s article shows you how!
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!