Beispiel #1
0
        private int _cellsBusy; // no need for volatile as we only update with Interlocked.CompareExchange

        /// <summary>
        ///     Returns the size in bytes occupied by an Striped64 instance.
        /// </summary>
        /// <param name="instance">instance for whch to calculate the size.</param>
        /// <returns>The size of the instance in bytes.</returns>
        public static int GetEstimatedFootprintInBytes(Striped64 instance)
        {
            var cells        = instance.Cells;
            var cellsLength  = cells?.Length ?? 0;
            var nonNullCells = 0;

            if (cells != null)
            {
                foreach (var cell in cells)
                {
                    if (cell != null)
                    {
                        nonNullCells++;
                    }
                }
            }

            return(AtomicLong.SizeInBytes +          // base
                   sizeof(int) +                     // cellsBusy
                   IntPtr.Size +                     // cells reference
                   cellsLength * IntPtr.Size +       // size of array of references to cells
                   nonNullCells * Cell.SizeInBytes); // size of non null cells
        }
 /// <summary>
 ///     Returns the size in bytes occupied by an Striped64 instance.
 /// </summary>
 /// <param name="instance">instance for whch to calculate the size.</param>
 /// <returns>The size of the instance in bytes.</returns>
 public static int GetEstimatedFootprintInBytes(StripedLongAdder instance)
 {
     return(Striped64.GetEstimatedFootprintInBytes(instance));
 }