3 Star 3 Fork 1

Gitee 极速下载/kbengine-unity3d-plugins

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/kbengine/kbengine_unity3d_plugins
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
ObjectPool.cs 674 Bytes
一键复制 编辑 原始数据 按行查看 历史
zhao enze 提交于 8年前 . 优化对象池结构
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading;
namespace KBEngine
{
/// <summary>
/// 简单的对象池
/// </summary>
/// <typeparam name="T">对象类型</typeparam>
public class ObjectPool<T> where T : new()
{
private static Stack<T> _objects = new Stack<T>();
private static T v;
public static T createObject()
{
lock (_objects)
{
if (_objects.Count > 0)
{
v = _objects.Pop();
return v;
}
else
{
return new T();
}
}
}
public static void reclaimObject(T item)
{
lock (_objects)
{
_objects.Push(item);
}
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/mirrors/kbengine-unity3d-plugins.git
git@gitee.com:mirrors/kbengine-unity3d-plugins.git
mirrors
kbengine-unity3d-plugins
kbengine-unity3d-plugins
master

搜索帮助