Posts Tagged dictionary

C++ For C# Developers: Part 46 – Other Containers Library

Tags: , , ,

Array-like containers aren’t the only containers we need. Today we’ll look at the non-array containers the C++ Standard Library provides, including its equivalents of Dictionary, HashSet, and LinkedList.

Read the rest of this article »

No Comments

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

Which Hash Set is Fastest?

Tags: , , ,

Say you need to keep track of things you’ve already done, perhaps to avoid doing them again. What’s the fastest way to do that? HashSet<T> seems like a natural fit, so you might choose that without a second thought. But is it faster than similar collections like Hashtable and Dictionary<TKey, TValue>? Today’s article puts all three to the test to see which one can insert elements, check for containment, and remove elements the quickest. Read on for the surprising results!

Read the rest of this article »

2 Comments

Do Foreach Loops Create Garbage?

Tags: , , , , ,

We know that we should reduce the garbage our code produces to lighten the load on Unity’s garbage collector. The trouble is that many of the ways we’re creating garbage are hidden from us. One such way to inadvertently create a lot of garbage is to use a foreach loop… at least that’s what we’ve been told. Do foreach loops really create garbage for all types of arrays, lists, dictionaries, and the rest of the collections? Do they create garbage for every loop or just the first one? Today’s article investigates to put these questions to rest. Are you safe using foreach loops or should you re-write everything to use for. Read on to find out!

Read the rest of this article »

8 Comments

Optimize Algorithms and Data Structures First

Tags: , , , ,

Today’s article is both a reminder to optimize your algorithms and data structures before your code and a demonstration of the payoff you’ll get by doing so. By choosing the most effective algorithm and data structure to solve your problem you’ll reap huge rewards in performance. A 10x, 100x, or even bigger boost is easily attainable.

Read the rest of this article »

No Comments

Int Keys: Object vs. Dictionary vs. Array vs. Vector

Tags: , , , , , , , ,

Given that Object and Dictionary can have int keys and that int keys are faster than String keys, a natural performance test follows: which class is fastest at reading from and writing to those int keys? Is there a difference between the four Vector classes? Today’s article performs just that test and comes up with the answers.

Read the rest of this article »

8 Comments

String Keys vs. Int Keys

Tags: , , , , , ,

Now that we know you can use int keys with Object, it’s time to test whether or not this is any faster than String keys. Today’s article does just that and also tests int and String keys with Dictionary.

Read the rest of this article »

10 Comments

If-Else Trees vs. Array and Vector

Tags: , , , , , ,

We’ve seen that if-else trees are way faster than Object, Dictionary, and even switch at key-value mapping, but how do they stack up against Array and Vector? Today’s article puts them to the test and uncovers some unexpected results.

Read the rest of this article »

8 Comments

450x Speed Up Copying Between Collections

Tags: , , , , ,

Programming in AS3 invariably involves choosing between various collections: Array, Vector, Dictionary, Object, ByteArray, and so on. What if you need to quickly copy between them? Your choice of collection could result in a 450x slowdown in your app… or a 450x speedup!

Read the rest of this article »

7 Comments