Posts Tagged virtual function

C++ For C# Developers: Part 52 – Idioms and Best Practices

Tags: , , , , , , , ,

As a very large language used for a very wide range of purposes over many decades, C++ can be written in a lot of different ways. Today we’ll look at some of the norms for “modern” C++ to get a sense of how code is normally written.

Read the rest of this article »

6 Comments

C++ For C# Developers: Part 14 – Inheritance

Tags: , , , , ,

Now that we know how to initialize structs and other types in C++, we can take a look at inheritance and learn how to make structs derive from each other. There’s a lot of extended functionality here compared to C# class inheritance. Read on to learn the basics as well as advanced features like multiple inheritance and virtual inheritance!

Read the rest of this article »

3 Comments

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

DIY Virtual Functions in Burst

Tags: , , , , ,

Now that we’ve seen how function pointers work and perform in Burst, let’s use them to build a higher-level feature: virtual functions!

Read the rest of this article »

3 Comments

5 Common Misuses of Collections

Tags: , , , , , , ,

Collection types like List<T> and Dictionary<TKey, TValue> are fundamental tools in C#. Sadly, I keep seeing the same misuses of them in codebase after codebase. Today we’ll look at the top 5 problems and learn how to easily avoid them!

Read the rest of this article »

13 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

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 25 – Full Type Hierarchy

Tags: , , ,

So far we’ve had C++ classes that derive from other classes, but not their interfaces. Today we’ll make C++ classes implement all their interfaces to form a full type hierarchy. Along the way we’ll learn about how inheritance works in C++, specifically the esoteric form known as “virtual inheritance.”

Read the rest of this article »

No Comments

C++ Scripting: Part 19 – Implement C# Interfaces with C++ Classes

Tags: , , , ,

Implementing interfaces and deriving from classes is commonplace in many codebases. Today we’ll make it so C++ classes can implement C# interfaces and derive from C# classes. This means our C++ game code will be able to implement custom IComparer classes for sorting a List and derive custom EventArgs for dispatching in events. Read on to see how this is implemented and how to use it in our projects.

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