C# .Net allocation and freeing system is quite efficient but when you need to create a huge number of objects, it’s just not fast enough. So what you can do is try to recycle each object to avoid to recreate them. You will then just need to set their property.

In my tests, this class reduced the allocation time from 12 to 15 times:

public sealed class Heap<T> where T:class, new() {
    private readonly Stack<T> _stack = new Stack<T>();
    private int _count;
    public T Allocate() {
                if ( _count ==  ) {
                   return new T();
                } else {
                  return _stack.Pop();
    public void Free( T obj ) {
        _stack.Push( obj );

You might think that this process is really painful as you have to manually free every single objects you use. But in fact you just have to recycle most of the objects. If you forget some, that’s not really important (they will just get garbage collected).