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!
Posts Tagged delegate
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.
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.
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.
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!
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++.
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.
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!
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!
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!