コード例 #1
0
        public virtual void TestLargeSetOfByteArrays()
        {
            CauseGc();
            long before = GC.GetTotalMemory(false);

            object[] all = new object[1000000];
            for (int i = 0; i < all.Length; i++)
            {
                all[i] = new sbyte[Random().Next(3)];
            }
            CauseGc();
            long after = GC.GetTotalMemory(false);

            Console.WriteLine("mx:  " + RamUsageEstimator.HumanReadableUnits(after - before));
            Console.WriteLine("rue: " + RamUsageEstimator.HumanReadableUnits(ShallowSizeOf(all)));

            Guard = all;
        }
コード例 #2
0
        public virtual void TestSimpleByteArrays()
        {
            object[][] all = new object[0][];
            try
            {
                while (true)
                {
                    // Check the current memory consumption and provide the estimate.
                    CauseGc();

                    long estimated = ShallowSizeOf(all);
                    if (estimated > 50 * RamUsageEstimator.ONE_MB)
                    {
                        break;
                    }

                    Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "{0}\t{1}\t{2}", RamUsageEstimator.HumanReadableUnits(GC.GetTotalMemory(false)).PadLeft(10, ' '), RamUsageEstimator.HumanReadableUnits(GC.MaxGeneration).PadLeft(10, ' '), RamUsageEstimator.HumanReadableUnits(estimated).PadLeft(10, ' ')));

                    // Make another batch of objects.
                    object[] seg = new object[10000];
                    all = Arrays.CopyOf(all, all.Length + 1);
                    all[all.Length - 1] = seg;
                    for (int i = 0; i < seg.Length; i++)
                    {
                        seg[i] = new sbyte[Random().Next(7)];
                    }
                }
            }
#pragma warning disable 168
            catch (System.OutOfMemoryException e)
#pragma warning restore 168
            {
                // Release and quit.
            }
        }
コード例 #3
0
        /// <summary> Computes (and stores) the estimated size of the cache Value </summary>
        /// <seealso cref="EstimatedSize">
        /// </seealso>
        public virtual void EstimateSize(RamUsageEstimator ramCalc)
        {
            long size = ramCalc.EstimateRamUsage(Value);

            EstimatedSize = RamUsageEstimator.HumanReadableUnits(size, new System.Globalization.NumberFormatInfo());  // {{Aroush-2.9}} in Java, the formater is set to "0.#", so we need to do the same in C#
        }