Lucene.Net.Facet.Taxonomy.WriterCache.CompactLabelToOrdinal.GetMemoryUsage C# (CSharp) Method

GetMemoryUsage() private method

Returns an estimate of the amount of memory used by this table. Called only in this package. Memory is consumed mainly by three structures: the hash arrays, label repository and collision map.
private GetMemoryUsage ( ) : int
return int
        internal virtual int GetMemoryUsage()
        {
            int memoryUsage = 0;
            if (this.hashArrays != null)
            {
                // HashArray capacity is instance-specific.
                foreach (HashArray ha in this.hashArrays)
                {
                    // Each has 2 capacity-length arrays of ints.
                    memoryUsage += (ha.capacity * 2 * 4) + 4;
                }
            }
            if (this.labelRepository != null)
            {
                // All blocks are the same size.
                int blockSize = this.labelRepository.blockSize;
                // Each block has room for blockSize UTF-16 chars.
                int actualBlockSize = (blockSize * 2) + 4;
                memoryUsage += this.labelRepository.blocks.Count * actualBlockSize;
                memoryUsage += 8; // Two int values for array as a whole.
            }
            if (this.collisionMap != null)
            {
                memoryUsage += this.collisionMap.GetMemoryUsage();
            }
            return memoryUsage;
        }

Usage Example

 /// <summary>
 /// Returns the number of bytes in memory used by this object.
 /// </summary>
 public virtual int GetMemoryUsage()
 {
     return(cache == null ? 0 : cache.GetMemoryUsage());
 }