Posts Tagged typecast

C++ For C# Developers: Part 21 – Casting and RTTI

Tags: ,

Now that we’ve seen how types are implicitly converted in C++, we can see how they’re explicitly converted by casting. C++ offers a lot more kinds of casts than C# to control the conversion process. One of them—dynamic_cast—introduces the concept of Run-Time Type Information or RTTI, so we’ll go into that today as well.

Read the rest of this article »

4 Comments

C++ For C# Developers: Part 9 – Enumerations

Tags: , , ,

We’ll continue the series today by discussing enumerations, which is yet-another surprisingly-complex topic in C++. We actually have two closely related concepts of enumerations to go over today, so read on to learn all about both kinds!

Read the rest of this article »

7 Comments

IL2CPP Output for C# 7.3: Pattern Matching

Tags: , , , ,

Last week we started exploring the new features of C# 7.3 in Unity 2018.3 by delving into tuples. This week we’ll continue and look at pattern matching. Read on to see how the many forms of pattern matching are actually implemented by IL2CPP!

Read the rest of this article »

3 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 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

Three IL2CPP Optimizations

Tags: , , ,

This week we’ll take a break from the C++ Scripting series to explore three optimizations we can make to our C# code so that IL2CPP generates faster C++ code for us. We’ll cover three areas that yield big speedups: casting, array bounds checking, and null checking.

Read the rest of this article »

3 Comments

How to Recover Anonymous Types

Tags: , , , ,

When we just need a quick and dirty type to hold some values, C#’s anonymous types fit the bill: var person = { First="John", Last="Doe", Age=42 }. On the down side, since these types are anonymous they have no explicit type. The var variable is strongly typed, but you have to use the object type when passing them to other functions. But then how do you get the fields back out? Today’s article shows you how so that anonymous types will be more useful to you. Read on to find out how to recover anonymous types!

Read the rest of this article »

No Comments

From AS3 to C#, Part 15: Loops, Casts, and Operators

Tags: , ,

As with types and variables, there is a lot of subtlety in the differences between AS3 and C# when it comes to loops, casts, and operators. As core parts of the language, it’s important that we know all the little details of our most fundamental tools. Read on to learn what they have in common, what new operators C# offers, and what operators C# doesn’t have.

Read the rest of this article »

5 Comments

Converting Numbers to Ints

Tags: , , , , , ,

This is an extremely common task: converting a Number to an int. There are a lot of ways to do it, but which is fastest in AS3? Today we’ll look at a performance test app that attempts to find the fastest way to accomplish this. The answer just may surprise you!

Read the rest of this article »

14 Comments

Casting Questions Answered

Tags: , , , ,

You, my dear readers, have posed many fine questions and chimed in with many excellent suggestions to my previous articles on typecasting and today I will answer them! (for newcomers to this series, read on for tips showing how to easily speed up your casts by 200x or more)

Read the rest of this article »

9 Comments