Ejemplo n.º 1
0
        internal static void PurgeTextures(long _purgeTotalBytes)
        {
            Contract.AssertPositive(_purgeTotalBytes);

            Debug.TraceLn($"Attempting to purge {_purgeTotalBytes.AsDataSize()} from currently loaded textures");

            // For portability purposes
            if (IntPtr.Size == 8)
            {
                var purgeTotalBytes = _purgeTotalBytes;
                lock (MostRecentList) {
                    long totalPurge = 0;
                    while (purgeTotalBytes > 0 && MostRecentList.Count > 0)
                    {
                        if (MostRecentList.Last().TryGetTarget(out var target))
                        {
                            var textureSize = unchecked ((long)target.MemorySize);
                            Debug.TraceLn($"Purging {target.SafeName()} ({textureSize.AsDataSize()})");
                            purgeTotalBytes         -= textureSize;
                            totalPurge              += textureSize;
                            target.CurrentRecentNode = null;
                            target.Dispose(true);
                        }
                        MostRecentList.RemoveLast();
                    }
                    Debug.TraceLn($"Total Purged: {totalPurge.AsDataSize()}");
                }
            }
            else
            {
                // For 32-bit, truncate down to an integer so this operation goes a bit faster.
                Contract.AssertLessEqual(_purgeTotalBytes, (long)uint.MaxValue);
                var purgeTotalBytes = unchecked ((uint)_purgeTotalBytes);
                lock (MostRecentList) {
                    uint totalPurge = 0;
                    while (purgeTotalBytes > 0 && MostRecentList.Count > 0)
                    {
                        if (MostRecentList.Last().TryGetTarget(out var target))
                        {
                            var textureSize = unchecked ((uint)target.MemorySize);
                            Debug.TraceLn($"Purging {target.SafeName()} ({textureSize.AsDataSize()})");
                            purgeTotalBytes         -= textureSize;
                            totalPurge              += textureSize;
                            target.CurrentRecentNode = null;
                            target.Dispose(true);
                        }
                        MostRecentList.RemoveLast();
                    }
                    Debug.TraceLn($"Total Purged: {totalPurge.AsDataSize()}");
                }
            }
        }