Posts Tagged GC

Enumerables Without the Garbage: Part 6

We’re nearing the end of the series to build a no-garbage replacement for System.Linq. Today we tackle functions that work on already-sorted ranges and functions that work on ranges that are in heap order. These include common set operations like “union” and “intersection”. Read on to see how to use them and for the updated library that you can use to eliminate your garbage creation!

Read the rest of this entry »

Tags: , , , , , , ,

No Comments

Enumerables Without the Garbage: Part 5

This week we continue with iterators to get the functionality of IEnumerable without the nasty garbage creation. This week the little iterator library gets support for sorting and binary searching. Read on for the details!

Read the rest of this entry »

Tags: , , , , , , ,

2 Comments

Enumerables Without the Garbage: Part 4

Back from a brief break, we pick up this week by finishing up the “modifying sequence operations” with some gems like RandomShuffle and go through the “partitions” category with functions like Partition and IsPartitioned. These are all solid algorithms with a lot of potential uses, so read on to see how to use them with iterators and for the source code that implements them!

Read the rest of this entry »

Tags: , , , , , , ,

No Comments

Enumerables Without the Garbage: Part 3

Continuing the series this week we’ll delve into the iterator functions that modify the sequence. This includes handy tools like Copy, SwapRanges, and Transform. Of course this is all done without creating any garbage! Read on to see how and for the full source code.

Read the rest of this entry »

Tags: , , , , , , ,

No Comments

Enumerables Without the Garbage: Part 2

Last week’s article introduced the concept of iterators as an alternative to the GC-heavy IEnumerable. Today’s article expands the iterator library to include a bunch of more functions to make it useful. Think of these like the extension functions in System.Linq: Any, IndexOf, etc. These have all been tailored to iterators and none of them will create any garbage whatsoever.

Read the rest of this entry »

Tags: , , , , , , ,

No Comments

Enumerables Without the Garbage: Part 1

In C#, just about everything is an IEnumerable. Since LINQ syntax, foreach loops, and the System.Linq namespace are all designed to work with IEnumerable, you’ve got lots of tools to use. Unfortunately, the core of IEnumerable is the GetEnumerator function which usually creates garbage and eventually causes memory fragmentation and GC framerate spikes. Do we simply stop using all of these nice tools? Normally the answer is “yes”, but today’s article shows you another way.

Read the rest of this entry »

Tags: , , , , , ,

1 Comment

Even More Ways Structs Create Garbage

Last time we saw that calling a non-default constructor on a generic struct (MyStruct<T>) causes garbage creation. That garbage creation is subtle, but can have big impacts on framerate and memory usage. Today we’ll see two more ways that structs can create garbage and hopefully avoid some pitfalls. Read on to find out how!

Read the rest of this entry »

Tags: , , ,

2 Comments

Another Way Structs Create Garbage

As Unity programmers, the garbage collector is sadly our enemy. C# structs are often a great tool to avoid allocating objects that need to later be garbage-collected. This isn’t always the case though. Sometimes even a struct can allocate garbage. Today’s article points out one of those ways so you won’t be fooled into thinking you’ve stopped the GC just because you’re using a struct. Read on to learn more!

Read the rest of this entry »

Tags: , ,

2 Comments

FastList: A Solution to List’s GC Problems?

As we know, foreach loops create garbage when used with a List<T>. This happens the first time you iterate over one and it happens every time thereafter. A comment on that article shared a link to a class called FastList that was written expressly to solve the GC issue. Does it? How does its performance compare to plain old List? Today’s article puts it to the test to find out!

Read the rest of this entry »

Tags: ,

5 Comments

Using Structs to Avoid Creating Garbage

It’s easy to forget about struct in C#. After all, it’s not available in other languages like Java or AS3 and it seems to have fewer features than good old class. But struct can really help you out when it comes to garbage creation! Today’s article discusses some strategies to get the most out of struct. Read on to learn how to use structs to put a stop to that pesky garbage collector!

Read the rest of this entry »

Tags: , , , ,

No Comments