public static UnityDataFormatter GetFormatter <T>() where T : IFormatter
        {
            if (_formatterPools == null)
            {
                _formatterPools = new Dictionary <System.Type, ObjectCachePool <UnityDataFormatter> >();
            }

            var tp = typeof(T);
            UnityDataFormatter formatter;

            if (_formatterPools.ContainsKey(tp))
            {
                formatter = _formatterPools[tp].GetInstance();
            }
            else
            {
                var pool = new ObjectCachePool <UnityDataFormatter>(10, () =>
                {
                    var f            = new UnityDataFormatter(System.Activator.CreateInstance <T>());
                    f._pooledTypeKey = typeof(T);
                    return(f);
                });
                _formatterPools.Add(tp, pool);
                formatter = pool.GetInstance();
            }

            return(formatter);
        }
Exemplo n.º 2
0
 void IDisposable.Dispose()
 {
     _table.Clear();
     if (_tempTokens == null)
     {
         _tempTokens = new ObjectCachePool <StateToken>(TEMP_STACKSIZE);
     }
     _tempTokens.Release(this);
 }
Exemplo n.º 3
0
    void Awake()
    {
        if (instance_ == null)
        {
            instance_ = this;
            GameObject go = new GameObject("CachePool");
            mTrans_ = go.transform;
            mTrans_.SetParent(transform, false);
        }
        else
        {
//			Logger.Log (string.Format("DDestory----> {0}",name),ClientConfig.LOG_COLOR_ERROR);
            Destroy(gameObject);
        }
    }