Posts Tagged boxing

Collections Without the Boxing

Tags: , , , , ,

In last week’s tips for using collections like List<T>, we saw how struct types are sometimes boxed resulting in GC allocations. This week we’ll see how to avoid boxing and learn some of the clever tricks that .NET collection types use to make this possible.

Read the rest of this article »

4 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

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 28 – Value Types Overhaul

Tags: , , , , , ,

Value types like int, structs, and enums seem simple, but much of what we think we know about them just isn’t true. This article explores how value types actually work in C# and uses that knowledge to improve how they’re implemented in the C++ scripting system.

Read the rest of this article »

No Comments

C++ Scripting: Part 17 – Boxing and Unboxing

Tags: , , , , ,

The GitHub project is closing in on supporting all the “must have” features. Today’s article tackles “boxing” and “unboxing” so our C++ game code will be able to convert types like int into an object and then convert an object back into an int. Usually we want to avoid this because it creates garbage for the GC to later collect and ruins type safety, but sometimes an API like Debug.Log insists that we pass it an object. Read on to see how to use boxing and unboxing in C++!

Read the rest of this article »

No Comments

Garbage Gotchas

Tags: , , , , , , ,

Sometimes it seems like Unity programming is a minefield. Plenty of innocuous-looking code secretly creates garbage and eventually the GC runs and causes a frame hitch. Today’s article is about some of those less-obvious ways to create garbage.

Read the rest of this article »

2 Comments