Posts Tagged enumerator

C++ Scripting: Part 27 – Foreach Loops

Tags: , , ,

C++ doesn’t have a foreach keyword, but it does have an equivalent in “range for loops”. Today we’ll implement support for them so we can easily loop over arrays and types implementing IEnumerable and IEnumerable<T>.

Read the rest of this article »

No Comments

Iterators vs. Callbacks: Performance and Garbage

Tags: , , , , , , ,

Iterator functions and their ability to yield return values then continue on really come in handy for a variety of situations. Unfortunately, they come with some pretty serious performance and garbage creation drawbacks. So today’s article explores alternatives in various forms of callbacks: delegates, interfaces, and classes. Can they perform better than iterator functions? Can they avoid garbage creation? Read on to find out!

Read the rest of this article »

2 Comments

Iterating Multiple Lists In Order: Part 2

Tags: , ,

Last week I presented a problem: how do you iterate over multiple lists of multiple types in the order of some common field? For example, how would you iterate over a list of Player and a list of Enemy by both of their Health fields? In that article I showed two solutions to iterate over two lists in this way. What I didn’t show were any solutions to handle more than two lists. What if you needed to also iterate over a list of NPC? Today’s article discusses how to tackle this problem and ends up with a handy utility class that you can use for your own types no matter how many lists you have. Read on to see how!

Read the rest of this article »

No Comments

Unity Coroutine Performance

Tags: , ,

Unity’s coroutine support allows you to easily create pseudo-threads and write synchronous-looking code that doesn’t block the rest of the app. They can be very handy for a variety of tasks. Before using them, we should understand the performance cost. Today’s article takes a look at the cost of starting a coroutine as well as the cost of running it. Just how expensive are they? Read on to find out!

Read the rest of this article »

11 Comments