コード例 #1
0
		public virtual void  TestBasic()
		{
			System.String string_Renamed = new System.Text.StringBuilder("test str").ToString();
			RamUsageEstimator rue = new RamUsageEstimator();
			long size = rue.EstimateRamUsage(string_Renamed);
			System.Console.Out.WriteLine("size:" + size);
			
			string_Renamed = new System.Text.StringBuilder("test strin").ToString();
			size = rue.EstimateRamUsage(string_Renamed);
			System.Console.Out.WriteLine("size:" + size);
			
			Holder holder = new Holder();
			holder.holder = new Holder("string2", 5000L);
			size = rue.EstimateRamUsage(holder);
			System.Console.Out.WriteLine("size:" + size);
			
			System.String[] strings = new System.String[]{new System.Text.StringBuilder("test strin").ToString(), new System.Text.StringBuilder("hollow").ToString(), new System.Text.StringBuilder("catchmaster").ToString()};
			size = rue.EstimateRamUsage(strings);
			System.Console.Out.WriteLine("size:" + size);
		}
コード例 #2
0
		/// <summary> If set, will be used to estimate size for all CacheEntry objects 
		/// dealt with.
		/// </summary>
		public void  SetRamUsageEstimator(RamUsageEstimator r)
		{
			ramCalc = r;
		}
コード例 #3
0
ファイル: IndexStorage.cs プロジェクト: nwendel/ravendb
		    public LowMemoryHandlerStatistics GetStats()
		    {
			    var cacheEntries = FieldCache_Fields.DEFAULT.GetCacheEntries();
			    var memorySum = cacheEntries.Sum(x =>
			    {
				    var curEstimator = new RamUsageEstimator(false);
				    return curEstimator.EstimateRamUsage(x);
			    });
			    return new LowMemoryHandlerStatistics
			    {
					Name = "LuceneLowMemoryHandler",
					EstimatedUsedMemory = memorySum,
					Metadata = new
					{
						CachedEntriesAmount = cacheEntries.Length
					}
			    };
		    }
コード例 #4
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.
            }
        }
コード例 #5
0
 /// <summary>
 /// Return the memory usage of this instance. </summary>
 public long RamBytesUsed()
 {
     return(RamUsageEstimator.AlignObjectSize(3 * RamUsageEstimator.NUM_BYTES_OBJECT_REF) + docIDs.RamBytesUsed() + offsets.RamBytesUsed());
 }
コード例 #6
0
 /// <summary> If set, will be used to estimate size for all CacheEntry objects
 /// dealt with.
 /// </summary>
 public void  SetRamUsageEstimator(RamUsageEstimator r)
 {
     ramCalc = r;
 }
コード例 #7
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#
        }
コード例 #8
0
        public virtual void TestSimpleByteArrays()
        {
            MemoryMXBean memoryMXBean = ManagementFactory.MemoryMXBean;

            object[][] all = new object[0][];
            try
            {
                while (true)
                {
                    // Check the current memory consumption and provide the estimate.
                    CauseGc();
                    MemoryUsage mu        = memoryMXBean.HeapMemoryUsage;
                    long        estimated = ShallowSizeOf(all);
                    if (estimated > 50 * RamUsageEstimator.ONE_MB)
                    {
                        break;
                    }

                    Console.WriteLine(string.format(Locale.ROOT, "%10s\t%10s\t%10s", RamUsageEstimator.humanReadableUnits(mu.Used), RamUsageEstimator.humanReadableUnits(mu.Max), RamUsageEstimator.humanReadableUnits(estimated)));

                    // 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)];
                    }
                }
            }
            catch (System.OutOfMemoryException e)
            {
                // Release and quit.
            }
        }
コード例 #9
0
        public virtual void TestSanity()
        {
            Assert.IsTrue(RamUsageEstimator.SizeOf("test string") > RamUsageEstimator.ShallowSizeOfInstance(typeof(string)));

            Holder holder = new Holder();

            holder.holder = new Holder("string2", 5000L);
            Assert.IsTrue(RamUsageEstimator.SizeOf(holder) > RamUsageEstimator.ShallowSizeOfInstance(typeof(Holder)));
            Assert.IsTrue(RamUsageEstimator.SizeOf(holder) > RamUsageEstimator.SizeOf(holder.holder));

            Assert.IsTrue(RamUsageEstimator.ShallowSizeOfInstance(typeof(HolderSubclass)) >= RamUsageEstimator.ShallowSizeOfInstance(typeof(Holder)));
            Assert.IsTrue(RamUsageEstimator.ShallowSizeOfInstance(typeof(Holder)) == RamUsageEstimator.ShallowSizeOfInstance(typeof(HolderSubclass2)));

            string[] strings = new string[] { "test string", "hollow", "catchmaster" };
            Assert.IsTrue(RamUsageEstimator.SizeOf(strings) > RamUsageEstimator.ShallowSizeOf(strings));
        }
コード例 #10
0
ファイル: WAH8DocIdSet.cs プロジェクト: leotohill/lucene.net
 /// <summary>
 /// Return the memory usage of this class in bytes. </summary>
 public long RamBytesUsed()
 {
     return(RamUsageEstimator.AlignObjectSize(3 * RamUsageEstimator.NUM_BYTES_OBJECT_REF + 2 * RamUsageEstimator.NUM_BYTES_INT) + RamUsageEstimator.SizeOf(Data) + Positions.RamBytesUsed() + WordNums.RamBytesUsed());
 }