/// <summary> /// Release the buffer into the reusable pool. /// </summary> public bool Recycle (bool threadSafe = true) { #if RECYCLE_BUFFERS #if UNITY_EDITOR if (mCounter == 0) { #if DEBUG_BUFFERS UnityEngine.Debug.LogWarning("Releasing a buffer that's already in the pool: " + mUniqueID); #else UnityEngine.Debug.LogWarning("Releasing a buffer that's already in the pool"); #endif return false; } #endif if (Interlocked.Decrement(ref mCounter) > 0) return false; Clear(); if (mPoolCount < 250) { if (threadSafe) { lock (mPool) { ++mPoolCount; mPool.Enqueue(this); #if DEBUG_BUFFERS FastLog.Log("Recycling " + mUniqueID + " (" + mPool.Count + ")"); #endif } #endif } else { ++mPoolCount; mPool.Enqueue(this); #if DEBUG_BUFFERS FastLog.Log("Recycling " + mUniqueID + " (" + mPool.Count + ")"); #endif } } return true; }
public static T GetObject <T>(string key, T defVal) where T : new() { T obj = defVal; try { string objData = stringTable.GetValue(key, ""); obj = Newtonsoft.Json.JsonConvert.DeserializeObject <T>(objData); if (obj == null) { obj = defVal; } } catch (Exception ex) { FastLog.Log(ex); } return(obj); }
/// <summary> /// Create a new buffer, reusing an old one if possible. /// </summary> static public Buffer Create () { Buffer b = null; if (mPool.Count == 0) { b = new Buffer(); #if DEBUG_BUFFERS FastLog.Log("New " + b.mUniqueID); #endif } else { lock (mPool) { if (mPoolCount > 0) { --mPoolCount; b = mPool.Dequeue(); #if DEBUG_BUFFERS FastLog.Log("Existing " + b.mUniqueID + " (" + mPool.Count + ")"); #endif } else { b = new Buffer(); #if DEBUG_BUFFERS FastLog.Log("New " + b.mUniqueID); #endif } } } #if RECYCLE_BUFFERS #if UNITY_EDITOR && DEBUG_BUFFERS if (b.mCounter != 0) UnityEngine.Debug.LogWarning("Acquiring a buffer that's potentially in use: " + b.mUniqueID); #endif b.mCounter = 1; #endif return b; }