浏览代码

Added IDisposable functionality to ObjectPool (and ListPool)

/main
Peter Bay Bastian 8 年前
当前提交
7343f497
共有 5 个文件被更改,包括 62 次插入5 次删除
  1. 5
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Util/ListPool.cs
  2. 6
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Util/ObjectPool.cs
  3. 11
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphInspector.cs
  4. 33
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Util/PooledObject.cs
  5. 12
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Util/PooledObject.cs.meta

5
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Util/ListPool.cs


return s_ListPool.Get();
}
public static PooledObject<List<T>> GetDisposable()
{
return s_ListPool.GetDisposable();
}
public static void Release(List<T> toRelease)
{
s_ListPool.Release(toRelease);

6
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Util/ObjectPool.cs


using System;
using System.Collections.Generic;
using UnityEngine.Events;

if (m_ActionOnGet != null)
m_ActionOnGet(element);
return element;
}
public PooledObject<T> GetDisposable()
{
return new PooledObject<T>(this, Get());
}
public void Release(T element)

11
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphInspector.cs


{
if (node == null)
return;
var childNodes = ListPool<INode>.Get();
NodeUtils.DepthFirstCollectNodesFromNode(childNodes, node);
foreach (var childNode in childNodes)
using (var childNodes = ListPool<INode>.GetDisposable())
action(childNode);
NodeUtils.DepthFirstCollectNodesFromNode(childNodes.value, node);
foreach (var childNode in childNodes.value)
{
action(childNode);
}
ListPool<INode>.Release(childNodes);
}
}
}

33
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Util/PooledObject.cs


using System;
namespace UnityEngine.Graphing
{
public class PooledObject<T> : IDisposable where T : new()
{
private ObjectPool<T> m_ObjectPool;
public T value { get; private set; }
internal PooledObject(ObjectPool<T> objectPool, T value)
{
m_ObjectPool = objectPool;
this.value = value;
}
private void ReleaseUnmanagedResources()
{
m_ObjectPool.Release(value);
}
public void Dispose()
{
ReleaseUnmanagedResources();
GC.SuppressFinalize(this);
}
~PooledObject()
{
ReleaseUnmanagedResources();
}
}
}

12
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Util/PooledObject.cs.meta


fileFormatVersion: 2
guid: 7c55d0bf939d8458d8a982fb96a32364
timeCreated: 1483023793
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存