Class RamUsageEstimator
  
  Estimates the size (memory representation) of .NET objects.
This is a Lucene.NET INTERNAL API, use at your own risk
    Inheritance
    System.Object
    RamUsageEstimator
   
  
    Inherited Members
    
      System.Object.Equals(System.Object)
    
    
      System.Object.Equals(System.Object, System.Object)
    
    
      System.Object.GetHashCode()
    
    
      System.Object.GetType()
    
    
      System.Object.MemberwiseClone()
    
    
      System.Object.ReferenceEquals(System.Object, System.Object)
    
    
      System.Object.ToString()
    
   
  
  Assembly: Lucene.Net.dll
  Syntax
  
    public sealed class RamUsageEstimator
   
  Fields
  
  
    |
    Improve this Doc
  
  
    View Source
  
  
  Number of bytes to represent an array header (no content, but with alignments).
Declaration
  
    public static readonly int NUM_BYTES_ARRAY_HEADER
   
  Field Value
  
    
      
        | Type | Description | 
    
    
      
        | System.Int32 |  | 
    
  
  
    |
    Improve this Doc
  
  
    View Source
  
  NUM_BYTES_BOOLEAN
  
  
  Declaration
  
    public const int NUM_BYTES_BOOLEAN = 1
   
  Field Value
  
    
      
        | Type | Description | 
    
    
      
        | System.Int32 |  | 
    
  
  
    |
    Improve this Doc
  
  
    View Source
  
  NUM_BYTES_BYTE
  
  
  Declaration
  
    public const int NUM_BYTES_BYTE = 1
   
  Field Value
  
    
      
        | Type | Description | 
    
    
      
        | System.Int32 |  | 
    
  
  
    |
    Improve this Doc
  
  
    View Source
  
  NUM_BYTES_CHAR
  
  
  Declaration
  
    public const int NUM_BYTES_CHAR = 2
   
  Field Value
  
    
      
        | Type | Description | 
    
    
      
        | System.Int32 |  | 
    
  
  
    |
    Improve this Doc
  
  
    View Source
  
  NUM_BYTES_DOUBLE
  
  
  Declaration
  
    public const int NUM_BYTES_DOUBLE = 8
   
  Field Value
  
    
      
        | Type | Description | 
    
    
      
        | System.Int32 |  | 
    
  
  
    |
    Improve this Doc
  
  
    View Source
  
  NUM_BYTES_INT16
  NOTE: This was NUM_BYTES_SHORT in Lucene
Declaration
  
    public const int NUM_BYTES_INT16 = 2
   
  Field Value
  
    
      
        | Type | Description | 
    
    
      
        | System.Int32 |  | 
    
  
  
    |
    Improve this Doc
  
  
    View Source
  
  NUM_BYTES_INT32
  NOTE: This was NUM_BYTES_INT in Lucene
Declaration
  
    public const int NUM_BYTES_INT32 = 4
   
  Field Value
  
    
      
        | Type | Description | 
    
    
      
        | System.Int32 |  | 
    
  
  
    |
    Improve this Doc
  
  
    View Source
  
  NUM_BYTES_INT64
  NOTE: This was NUM_BYTES_LONG in Lucene
Declaration
  
    public const int NUM_BYTES_INT64 = 8
   
  Field Value
  
    
      
        | Type | Description | 
    
    
      
        | System.Int32 |  | 
    
  
  
    |
    Improve this Doc
  
  
    View Source
  
  NUM_BYTES_OBJECT_ALIGNMENT
  A constant specifying the object alignment boundary inside the .NET runtime. Objects will
always take a full multiple of this constant, possibly wasting some space.
Declaration
  
    public static readonly int NUM_BYTES_OBJECT_ALIGNMENT
   
  Field Value
  
    
      
        | Type | Description | 
    
    
      
        | System.Int32 |  | 
    
  
  
    |
    Improve this Doc
  
  
    View Source
  
  
  Number of bytes to represent an object header (no fields, no alignments).
Declaration
  
    public static readonly int NUM_BYTES_OBJECT_HEADER
   
  Field Value
  
    
      
        | Type | Description | 
    
    
      
        | System.Int32 |  | 
    
  
  
    |
    Improve this Doc
  
  
    View Source
  
  NUM_BYTES_OBJECT_REF
  Number of bytes this .NET runtime uses to represent an object reference.
Declaration
  
    public static readonly int NUM_BYTES_OBJECT_REF
   
  Field Value
  
    
      
        | Type | Description | 
    
    
      
        | System.Int32 |  | 
    
  
  
    |
    Improve this Doc
  
  
    View Source
  
  NUM_BYTES_SINGLE
  NOTE: This was NUM_BYTES_FLOAT in Lucene
Declaration
  
    public const int NUM_BYTES_SINGLE = 4
   
  Field Value
  
    
      
        | Type | Description | 
    
    
      
        | System.Int32 |  | 
    
  
  
    |
    Improve this Doc
  
  
    View Source
  
  ONE_GB
  
  
  Declaration
  
    public const long ONE_GB = 1073741824L
   
  Field Value
  
    
      
        | Type | Description | 
    
    
      
        | System.Int64 |  | 
    
  
  
    |
    Improve this Doc
  
  
    View Source
  
  ONE_KB
  
  
  Declaration
  
    public const long ONE_KB = 1024L
   
  Field Value
  
    
      
        | Type | Description | 
    
    
      
        | System.Int64 |  | 
    
  
  
    |
    Improve this Doc
  
  
    View Source
  
  ONE_MB
  
  
  Declaration
  
    public const long ONE_MB = 1048576L
   
  Field Value
  
    
      
        | Type | Description | 
    
    
      
        | System.Int64 |  | 
    
  
  Methods
  
  
    |
    Improve this Doc
  
  
    View Source
  
  
  AlignObjectSize(Int64)
  
  
  Declaration
  
    public static long AlignObjectSize(long size)
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | System.Int64 | size |  | 
    
  
  Returns
  
    
      
        | Type | Description | 
    
    
      
        | System.Int64 |  | 
    
  
  
    |
    Improve this Doc
  
  
    View Source
  
  
  HumanReadableUnits(Int64)
  Returns size in human-readable units (GB, MB, KB or bytes).
Declaration
  
    public static string HumanReadableUnits(long bytes)
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | System.Int64 | bytes |  | 
    
  
  Returns
  
    
      
        | Type | Description | 
    
    
      
        | System.String |  | 
    
  
  
    |
    Improve this Doc
  
  
    View Source
  
  
  
  Returns size in human-readable units (GB, MB, KB or bytes).
Declaration
  
    public static string HumanReadableUnits(long bytes, IFormatProvider df)
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | System.Int64 | bytes |  | 
      
        | System.IFormatProvider | df |  | 
    
  
  Returns
  
    
      
        | Type | Description | 
    
    
      
        | System.String |  | 
    
  
  
    |
    Improve this Doc
  
  
    View Source
  
  
  HumanSizeOf(Object)
  Return a human-readable size of a given object. 
Declaration
  
    public static string HumanSizeOf(object object)
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | System.Object | object |  | 
    
  
  Returns
  
    
      
        | Type | Description | 
    
    
      
        | System.String |  | 
    
  
  See Also
  
  
    |
    Improve this Doc
  
  
    View Source
  
  
  
  Return a human-readable size of a given object. 
Declaration
  
    public static string HumanSizeOf(object object, IFormatProvider df)
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | System.Object | object |  | 
      
        | System.IFormatProvider | df |  | 
    
  
  Returns
  
    
      
        | Type | Description | 
    
    
      
        | System.String |  | 
    
  
  
  
  
    |
    Improve this Doc
  
  
    View Source
  
  
  ShallowSizeOf(Object)
  Estimates a "shallow" memory usage of the given object. For arrays, this will be the
memory taken by array storage (no subreferences will be followed). For objects, this
will be the memory taken by the fields.
.NET object alignments are also applied.
Declaration
  
    public static long ShallowSizeOf(object obj)
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | System.Object | obj |  | 
    
  
  Returns
  
    
      
        | Type | Description | 
    
    
      
        | System.Int64 |  | 
    
  
  
    |
    Improve this Doc
  
  
    View Source
  
  
  ShallowSizeOfInstance(Type)
  Returns the shallow instance size in bytes an instance of the given class would occupy.
This works with all conventional classes and primitive types, but not with arrays
(the size then depends on the number of elements and varies from object to object).
Declaration
  
    public static long ShallowSizeOfInstance(Type clazz)
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | System.Type | clazz |  | 
    
  
  Returns
  
    
      
        | Type | Description | 
    
    
      
        | System.Int64 |  | 
    
  
  Exceptions
  
    
      
        | Type | Condition | 
    
    
      
        | System.ArgumentException | if clazzis an array class. | 
    
  
  See Also
  
  
    |
    Improve this Doc
  
  
    View Source
  
  
  SizeOf(Boolean[])
  Returns the size in bytes of the bool[] object. 
Declaration
  
    public static long SizeOf(bool[] arr)
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | System.Boolean[] | arr |  | 
    
  
  Returns
  
    
      
        | Type | Description | 
    
    
      
        | System.Int64 |  | 
    
  
  
    |
    Improve this Doc
  
  
    View Source
  
  
  SizeOf(Byte[])
  Returns the size in bytes of the byte[] object. 
Declaration
  
    public static long SizeOf(byte[] arr)
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | System.Byte[] | arr |  | 
    
  
  Returns
  
    
      
        | Type | Description | 
    
    
      
        | System.Int64 |  | 
    
  
  
    |
    Improve this Doc
  
  
    View Source
  
  
  SizeOf(Char[])
  Returns the size in bytes of the char[] object. 
Declaration
  
    public static long SizeOf(char[] arr)
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | System.Char[] | arr |  | 
    
  
  Returns
  
    
      
        | Type | Description | 
    
    
      
        | System.Int64 |  | 
    
  
  
    |
    Improve this Doc
  
  
    View Source
  
  
  SizeOf(Double[])
  Returns the size in bytes of the double[] object. 
Declaration
  
    public static long SizeOf(double[] arr)
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | System.Double[] | arr |  | 
    
  
  Returns
  
    
      
        | Type | Description | 
    
    
      
        | System.Int64 |  | 
    
  
  
    |
    Improve this Doc
  
  
    View Source
  
  
  SizeOf(Int16[])
  Returns the size in bytes of the short[] object. 
Declaration
  
    public static long SizeOf(short[] arr)
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | System.Int16[] | arr |  | 
    
  
  Returns
  
    
      
        | Type | Description | 
    
    
      
        | System.Int64 |  | 
    
  
  
    |
    Improve this Doc
  
  
    View Source
  
  
  SizeOf(Int32[])
  Returns the size in bytes of the int[] object. 
Declaration
  
    public static long SizeOf(int[] arr)
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | System.Int32[] | arr |  | 
    
  
  Returns
  
    
      
        | Type | Description | 
    
    
      
        | System.Int64 |  | 
    
  
  
    |
    Improve this Doc
  
  
    View Source
  
  
  SizeOf(Int64[])
  Returns the size in bytes of the long[] object. 
Declaration
  
    public static long SizeOf(long[] arr)
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | System.Int64[] | arr |  | 
    
  
  Returns
  
    
      
        | Type | Description | 
    
    
      
        | System.Int64 |  | 
    
  
  
    |
    Improve this Doc
  
  
    View Source
  
  
  SizeOf(Object)
  Estimates the RAM usage by the given object. It will
walk the object tree and sum up all referenced objects.
Resource Usage: this method internally uses a set of
every object seen during traversals so it does allocate memory
(it isn't side-effect free). After the method exits, this memory
should be GCed.
Declaration
  
    public static long SizeOf(object obj)
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | System.Object | obj |  | 
    
  
  Returns
  
    
      
        | Type | Description | 
    
    
      
        | System.Int64 |  | 
    
  
  
    |
    Improve this Doc
  
  
    View Source
  
  
  SizeOf(SByte[])
  Returns the size in bytes of the sbyte[] object. 
Declaration
  
    [CLSCompliant(false)]
public static long SizeOf(sbyte[] arr)
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | System.SByte[] | arr |  | 
    
  
  Returns
  
    
      
        | Type | Description | 
    
    
      
        | System.Int64 |  | 
    
  
  
    |
    Improve this Doc
  
  
    View Source
  
  
  SizeOf(Single[])
  Returns the size in bytes of the float[] object. 
Declaration
  
    public static long SizeOf(float[] arr)
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | System.Single[] | arr |  | 
    
  
  Returns
  
    
      
        | Type | Description | 
    
    
      
        | System.Int64 |  | 
    
  
  
    |
    Improve this Doc
  
  
    View Source
  
  
  SizeOf(UInt16[])
  Returns the size in bytes of the ushort[] object. 
Declaration
  
    [CLSCompliant(false)]
public static long SizeOf(ushort[] arr)
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | System.UInt16[] | arr |  | 
    
  
  Returns
  
    
      
        | Type | Description | 
    
    
      
        | System.Int64 |  | 
    
  
  
    |
    Improve this Doc
  
  
    View Source
  
  
  SizeOf(UInt32[])
  Returns the size in bytes of the uint[] object. 
Declaration
  
    [CLSCompliant(false)]
public static long SizeOf(uint[] arr)
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | System.UInt32[] | arr |  | 
    
  
  Returns
  
    
      
        | Type | Description | 
    
    
      
        | System.Int64 |  | 
    
  
  
    |
    Improve this Doc
  
  
    View Source
  
  
  SizeOf(UInt64[])
  Returns the size in bytes of the ulong[] object. 
Declaration
  
    [CLSCompliant(false)]
public static long SizeOf(ulong[] arr)
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | System.UInt64[] | arr |  | 
    
  
  Returns
  
    
      
        | Type | Description | 
    
    
      
        | System.Int64 |  | 
    
  
  See Also