Exemplo n.º 1
0
    public T GetOrCreate <T>(ProtoRecycleType type) where T : ProtoBase, new()
    {
        T result = Get <T>(type);

        if (result == null)
        {
            result = new T();
        }
        return(result);
    }
Exemplo n.º 2
0
    public void Recycle(ProtoRecycleType type, ProtoBase proto)
    {
        Stack <ProtoBase> stack;

        if (!pool.TryGetValue(type, out stack))
        {
            stack = new Stack <ProtoBase>();
            stack.Push(proto);
        }
        stack.Push(proto);
    }
Exemplo n.º 3
0
    public T Get <T>(ProtoRecycleType type) where T : ProtoBase, new()
    {
        Stack <ProtoBase> stack;
        T result = default(T);

        if (pool.TryGetValue(type, out stack))
        {
            ProtoBase p = null;
            p = stack.Pop();
            if (p != null)
            {
                result = p as T;
            }
        }

        return(result);
    }