Пример #1
0
    public static void ClearNoTouchZero(Dictionary <int, System.Collections.Queue> dic, Dictionary <int, PoolFlag_t> dicTouchZero)
    {
        if (dic != null)
        {
            if (dic.Count > 1)
            {
                foreach (KeyValuePair <int, System.Collections.Queue> data in dic)
                {
                    PoolFlag_t t_TouchZero = new PoolFlag_t();
                    t_TouchZero.Clear();
                    dicTouchZero.TryGetValue(data.Key, out t_TouchZero);
                    int cnt    = 0;
                    int delcnt = t_TouchZero.CanDel();
                    if (delcnt > 0)
                    {
                        System.Collections.Queue q = data.Value;
                        cnt = q.Count;
                        if (cnt > 1)
                        {
                            //清三分之一
                            for (int i = 0; i < delcnt; i++)
                            {
                                System.Object obj = q.Dequeue();
                                obj = null;
                            }
                        }
                    }
                    t_TouchZero.InPool -= delcnt;
                    t_TouchZero.total  -= delcnt;

                    dicTouchZero[data.Key] = t_TouchZero;
                }
            }
        }
    }
Пример #2
0
    public static void DeleteArray <T>(ref T[] array)
    {
#if HEAPPOOL_PERF_TEST
        ++deleteCount;
        deleteTimer.Start();
#endif

        Dictionary <int, Queue> qDic = null;
        int size = array.Length;
        if (false == m_vQueueArrayDic.TryGetValue(typeof(T), out qDic))
        {
            qDic = new Dictionary <int, Queue>();
            m_vQueueArrayDic.Add(typeof(T), qDic);
        }

        Queue q = null;
        if (false == qDic.TryGetValue(size, out q))
        {
            q = new Queue();
            qDic.Add(size, q);
        }

        Dictionary <int, PoolFlag_t> dicBool = null;

        if (m_vTouchZeroDic.TryGetValue(typeof(T), out dicBool))
        {
            //这个池见底了。
            PoolFlag_t pf = dicBool[size];
            pf.InPool    += 1;
            pf.NotInPool -= 1;
            dicBool[size] = pf;
        }
        q.Enqueue(array);
        array = null;
#if HEAPPOOL_PERF_TEST
        deleteTimer.Stop();
        deleteTime = (float)newTimer.ElapsedMilliseconds / deleteCount;
#endif
    }
Пример #3
0
    private static float deleteTime; // 每次delete的时间,ms
#endif

    private static T[] internal_NewArrayToLarger <T>(int count)
    {
#if HEAPPOOL_PERF_TEST
        ++newCount;
        cachePer = (float)cacheHitCount / newCount;
#endif
        //int doubleCount = count << 2;
        //int doubleCount = Games.TLBB.Util.GameUtil.GetNearest2N(count);
        int doubleCount = 2 * count;
        Dictionary <int, PoolFlag_t> dicBool = null;
        Dictionary <int, Queue>      qDic    = null;

        if (m_vQueueArrayDic.TryGetValue(typeof(T), out qDic))
        {
            Queue queue = null;

            if (qDic.TryGetValue(doubleCount, out queue))
            {
                if (queue.Count > 0)
                {
#if HEAPPOOL_PERF_TEST
                    ++cacheHitCount;
#endif

                    if (m_vTouchZeroDic.TryGetValue(typeof(T), out dicBool))
                    {
                        //这个池见底了。
                        PoolFlag_t pf = dicBool[doubleCount];
                        pf.InPool           -= 1;
                        pf.NotInPool        += 1;
                        dicBool[doubleCount] = pf;
                    }

                    return(queue.Dequeue() as T[]);
                }
                else
                {
#if HEAPPOOL_PERF_TEST
                    ++newQueueEmptyCount;
#endif
                }
            }
#if HEAPPOOL_PERF_TEST
            else
            {
                if (qDic.TryGetValue(doubleCount * 2, out queue))
                {
                    if (queue.Count > 0)
                    {
#if HEAPPOOL_PERF_TEST
                        ++cacheHitCount;
#endif
                        return(queue.Dequeue() as T[]);
                    }
                    else
                    {
#if HEAPPOOL_PERF_TEST
                        ++newQueueEmptyCount;
#endif
                    }
                }
                ++newCountCount;
            }
#endif
        }
#if HEAPPOOL_PERF_TEST
        else
        {
            ++newTypeCount;
        }
#endif

        if (m_vTouchZeroDic.TryGetValue(typeof(T), out dicBool))
        {
            //这个池见底了。
            PoolFlag_t pf = new PoolFlag_t();
            dicBool.TryGetValue(doubleCount, out pf);
            pf.InPool            = 0;
            pf.NotInPool        += 1;
            pf.total            += 1;
            dicBool[doubleCount] = pf;
        }
        else
        {
            dicBool = new Dictionary <int, PoolFlag_t>();
            PoolFlag_t pf = new PoolFlag_t();
            pf.Clear();
            pf.InPool            = 0;
            pf.NotInPool         = 1;
            pf.total             = 1;
            dicBool[doubleCount] = pf;
            m_vTouchZeroDic.Add(typeof(T), dicBool);
        }
        return(new T[doubleCount]);
    }