コード例 #1
0
        /// <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 != null ? 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
        }
コード例 #2
0
        /// <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 != null ? 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
        }