Posts Tagged delegate

C++ For C# Developers: Part 22 – Lambdas

Tags: , , , ,

Both C++ and C# have lambdas, but they have quite a few differences. Today we’ll go into how C++ lambdas work, including all their features and how they compare and contrast with C# lambdas. Read on to learn all the details!

Read the rest of this article »

1 Comment

Function Types: A Spectrum

Tags: , , , ,

C# gives us lots of types of functions for us to call. We must constantly decide between them. Should this function be static? Should it be virtual? There are many factors that go into making the decision. Today we’ll look at the function types as a spectrum and hopefully get a little perspective on our options.

Read the rest of this article »

5 Comments

C++ Scripting: Part 31 – Init Improvements

Tags: , ,

The C++ Scripting series continues today by going over some internal improvements that don’t add any features, but make the existing system more robust. We’ve lucked out in a couple of areas and today we’ll take the opportunity to fix them and learn about some inner workings of C++ and C# along the way.

Read the rest of this article »

5 Comments

IL2CPP Output: Abstract Classes, Sealed Classes, and Delegates

Tags: , , , ,

This week we continue to look at the C++ that IL2CPP outputs for C# to get a better understanding of what our C# is really doing. Today we’ll look at how abstract methods work, whether casting of sealed classes is faster than non-sealed classes, and what happens when creating a delegate.

Read the rest of this article »

No Comments

IL2CPP Function and Boxing Costs

Tags: , , , , ,

Today we continue looking at the C++ that IL2CPP generates for our C# code by calling various types of functions and using boxing and unboxing. Just how much performance overhead do these entail? Read on to find out!

Read the rest of this article »

2 Comments

C++ Scripting: Part 16 – Events

Tags: , , , ,

Last week’s article covered delegates, so it’s only natural that we follow up this week by covering events. Supporting delegates has laid a good foundation for supporting events, so let’s dive in and see how to implement and use them in C++.

Read the rest of this article »

No Comments

C++ Scripting: Part 15 – Delegates

Tags: , , , ,

This week’s article adds another major feature to the C++ scripting system: delegates. These are vital so C++ game code can use features like Unity’s UI system (a.k.a. UGUI). Without them, we wouldn’t be able to handle button clicks or other UI events. So read on to learn how these were implemented in the GitHub project.

Read the rest of this article »

No Comments

The Other CPU Cache

Tags: , , , , , ,

We’ve seen how using the CPU’s cache can lead to a 13x speedup, but that’s only utilizing one of the CPU’s cache types. Today’s article shows you how to go further by utilizing a whole other type of CPU caching!

Read the rest of this article »

6 Comments

Closures Without the GC

Tags: , , ,

Closures allow you to save the local variables of a function and access them later in a callback. Think of how lambdas can access the local variables of the function they’re declared in, even though the lambda itself is another function. Unfortunately, creating a lambda like this creates garbage for the GC to collect and you have no control over that process. Today’s article introduces an alternative that allows you to take control over the GC and still use nice, type-safe closures. Read on to learn how!

Read the rest of this article »

1 Comment

Delegates and Garbage Creation

Tags: , , , ,

Two facts are at odds in Unity programming. First, delegates like Action, Func, and EventHandler are extremely common with or without events. Second, the garbage collector is a huge source of CPU spikes and memory fragmentation in our games. Why are these facts at odds? Because code that uses delegates is almost always written in a way that creates garbage. It’s an extremely easy trap to fall into, but this article will show you how to get out of it!

Read the rest of this article »

12 Comments