Fork me on GitHub
  • API

    Show / Hide Table of Contents

    Class RamUsageEstimator

    Estimates the size (memory representation) of .NET objects.

    Note

    This API is for internal purposes only and might change in incompatible ways in the next release.

    Inheritance
    object
    RamUsageEstimator
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Lucene.Net.Util
    Assembly: Lucene.Net.dll
    Syntax
    public sealed class RamUsageEstimator

    Fields

    NUM_BYTES_ARRAY_HEADER

    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
    int
    See Also
    SizeOf(object)
    ShallowSizeOf(object)
    ShallowSizeOfInstance(Type)

    NUM_BYTES_BOOLEAN

    Estimates the size (memory representation) of .NET objects.

    Note

    This API is for internal purposes only and might change in incompatible ways in the next release.

    Declaration
    public const int NUM_BYTES_BOOLEAN = 1
    Field Value
    Type Description
    int
    See Also
    SizeOf(object)
    ShallowSizeOf(object)
    ShallowSizeOfInstance(Type)

    NUM_BYTES_BYTE

    Estimates the size (memory representation) of .NET objects.

    Note

    This API is for internal purposes only and might change in incompatible ways in the next release.

    Declaration
    public const int NUM_BYTES_BYTE = 1
    Field Value
    Type Description
    int
    See Also
    SizeOf(object)
    ShallowSizeOf(object)
    ShallowSizeOfInstance(Type)

    NUM_BYTES_CHAR

    Estimates the size (memory representation) of .NET objects.

    Note

    This API is for internal purposes only and might change in incompatible ways in the next release.

    Declaration
    public const int NUM_BYTES_CHAR = 2
    Field Value
    Type Description
    int
    See Also
    SizeOf(object)
    ShallowSizeOf(object)
    ShallowSizeOfInstance(Type)

    NUM_BYTES_DOUBLE

    Estimates the size (memory representation) of .NET objects.

    Note

    This API is for internal purposes only and might change in incompatible ways in the next release.

    Declaration
    public const int NUM_BYTES_DOUBLE = 8
    Field Value
    Type Description
    int
    See Also
    SizeOf(object)
    ShallowSizeOf(object)
    ShallowSizeOfInstance(Type)

    NUM_BYTES_INT16

    NOTE: This was NUM_BYTES_SHORT in Lucene

    Declaration
    public const int NUM_BYTES_INT16 = 2
    Field Value
    Type Description
    int
    See Also
    SizeOf(object)
    ShallowSizeOf(object)
    ShallowSizeOfInstance(Type)

    NUM_BYTES_INT32

    NOTE: This was NUM_BYTES_INT in Lucene

    Declaration
    public const int NUM_BYTES_INT32 = 4
    Field Value
    Type Description
    int
    See Also
    SizeOf(object)
    ShallowSizeOf(object)
    ShallowSizeOfInstance(Type)

    NUM_BYTES_INT64

    NOTE: This was NUM_BYTES_LONG in Lucene

    Declaration
    public const int NUM_BYTES_INT64 = 8
    Field Value
    Type Description
    int
    See Also
    SizeOf(object)
    ShallowSizeOf(object)
    ShallowSizeOfInstance(Type)

    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
    int
    See Also
    SizeOf(object)
    ShallowSizeOf(object)
    ShallowSizeOfInstance(Type)

    NUM_BYTES_OBJECT_HEADER

    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
    int
    See Also
    SizeOf(object)
    ShallowSizeOf(object)
    ShallowSizeOfInstance(Type)

    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
    int
    See Also
    SizeOf(object)
    ShallowSizeOf(object)
    ShallowSizeOfInstance(Type)

    NUM_BYTES_SINGLE

    NOTE: This was NUM_BYTES_FLOAT in Lucene

    Declaration
    public const int NUM_BYTES_SINGLE = 4
    Field Value
    Type Description
    int
    See Also
    SizeOf(object)
    ShallowSizeOf(object)
    ShallowSizeOfInstance(Type)

    ONE_GB

    One gigabyte bytes.

    Declaration
    public const long ONE_GB = 1073741824
    Field Value
    Type Description
    long
    See Also
    SizeOf(object)
    ShallowSizeOf(object)
    ShallowSizeOfInstance(Type)

    ONE_KB

    One kilobyte bytes.

    Declaration
    public const long ONE_KB = 1024
    Field Value
    Type Description
    long
    See Also
    SizeOf(object)
    ShallowSizeOf(object)
    ShallowSizeOfInstance(Type)

    ONE_MB

    One megabyte bytes.

    Declaration
    public const long ONE_MB = 1048576
    Field Value
    Type Description
    long
    See Also
    SizeOf(object)
    ShallowSizeOf(object)
    ShallowSizeOfInstance(Type)

    Methods

    AlignObjectSize(long)

    Aligns an object size to be the next multiple of NUM_BYTES_OBJECT_ALIGNMENT.

    Declaration
    public static long AlignObjectSize(long size)
    Parameters
    Type Name Description
    long size
    Returns
    Type Description
    long
    See Also
    SizeOf(object)
    ShallowSizeOf(object)
    ShallowSizeOfInstance(Type)

    HumanReadableUnits(long)

    Returns size in human-readable units (GB, MB, KB or bytes).

    Declaration
    public static string HumanReadableUnits(long bytes)
    Parameters
    Type Name Description
    long bytes
    Returns
    Type Description
    string
    See Also
    SizeOf(object)
    ShallowSizeOf(object)
    ShallowSizeOfInstance(Type)

    HumanReadableUnits(long, IFormatProvider)

    Returns size in human-readable units (GB, MB, KB or bytes).

    Declaration
    public static string HumanReadableUnits(long bytes, IFormatProvider df)
    Parameters
    Type Name Description
    long bytes
    IFormatProvider df
    Returns
    Type Description
    string
    See Also
    SizeOf(object)
    ShallowSizeOf(object)
    ShallowSizeOfInstance(Type)

    HumanSizeOf(object)

    Return a human-readable size of a given object.

    Declaration
    public static string HumanSizeOf(object @object)
    Parameters
    Type Name Description
    object object
    Returns
    Type Description
    string
    See Also
    SizeOf(object)
    HumanReadableUnits(long)

    HumanSizeOf(object, IFormatProvider)

    Return a human-readable size of a given object.

    Declaration
    public static string HumanSizeOf(object @object, IFormatProvider df)
    Parameters
    Type Name Description
    object object
    IFormatProvider df
    Returns
    Type Description
    string
    See Also
    SizeOf(object)
    HumanReadableUnits(long)

    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
    object obj
    Returns
    Type Description
    long
    See Also
    SizeOf(object)
    ShallowSizeOf(object)
    ShallowSizeOfInstance(Type)

    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
    Type clazz
    Returns
    Type Description
    long
    Exceptions
    Type Condition
    ArgumentException

    if clazz is an array class.

    See Also
    ShallowSizeOf(object)

    SizeOf(bool[])

    Returns the size in bytes of the bool[] object.

    Declaration
    public static long SizeOf(bool[] arr)
    Parameters
    Type Name Description
    bool[] arr
    Returns
    Type Description
    long
    See Also
    SizeOf(object)
    ShallowSizeOf(object)
    ShallowSizeOfInstance(Type)

    SizeOf(byte[])

    Returns the size in bytes of the byte[] object.

    Declaration
    public static long SizeOf(byte[] arr)
    Parameters
    Type Name Description
    byte[] arr
    Returns
    Type Description
    long
    See Also
    SizeOf(object)
    ShallowSizeOf(object)
    ShallowSizeOfInstance(Type)

    SizeOf(char[])

    Returns the size in bytes of the char[] object.

    Declaration
    public static long SizeOf(char[] arr)
    Parameters
    Type Name Description
    char[] arr
    Returns
    Type Description
    long
    See Also
    SizeOf(object)
    ShallowSizeOf(object)
    ShallowSizeOfInstance(Type)

    SizeOf(double[])

    Returns the size in bytes of the double[] object.

    Declaration
    public static long SizeOf(double[] arr)
    Parameters
    Type Name Description
    double[] arr
    Returns
    Type Description
    long
    See Also
    SizeOf(object)
    ShallowSizeOf(object)
    ShallowSizeOfInstance(Type)

    SizeOf(short[])

    Returns the size in bytes of the short[] object.

    Declaration
    public static long SizeOf(short[] arr)
    Parameters
    Type Name Description
    short[] arr
    Returns
    Type Description
    long
    See Also
    SizeOf(object)
    ShallowSizeOf(object)
    ShallowSizeOfInstance(Type)

    SizeOf(int[])

    Returns the size in bytes of the int[] object.

    Declaration
    public static long SizeOf(int[] arr)
    Parameters
    Type Name Description
    int[] arr
    Returns
    Type Description
    long
    See Also
    SizeOf(object)
    ShallowSizeOf(object)
    ShallowSizeOfInstance(Type)

    SizeOf(long[])

    Returns the size in bytes of the long[] object.

    Declaration
    public static long SizeOf(long[] arr)
    Parameters
    Type Name Description
    long[] arr
    Returns
    Type Description
    long
    See Also
    SizeOf(object)
    ShallowSizeOf(object)
    ShallowSizeOfInstance(Type)

    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
    object obj
    Returns
    Type Description
    long
    See Also
    SizeOf(object)
    ShallowSizeOf(object)
    ShallowSizeOfInstance(Type)

    SizeOf(sbyte[])

    Returns the size in bytes of the sbyte[] object.

    Declaration
    [CLSCompliant(false)]
    public static long SizeOf(sbyte[] arr)
    Parameters
    Type Name Description
    sbyte[] arr
    Returns
    Type Description
    long
    See Also
    SizeOf(object)
    ShallowSizeOf(object)
    ShallowSizeOfInstance(Type)

    SizeOf(float[])

    Returns the size in bytes of the float[] object.

    Declaration
    public static long SizeOf(float[] arr)
    Parameters
    Type Name Description
    float[] arr
    Returns
    Type Description
    long
    See Also
    SizeOf(object)
    ShallowSizeOf(object)
    ShallowSizeOfInstance(Type)

    SizeOf(ushort[])

    Returns the size in bytes of the ushort[] object.

    Declaration
    [CLSCompliant(false)]
    public static long SizeOf(ushort[] arr)
    Parameters
    Type Name Description
    ushort[] arr
    Returns
    Type Description
    long
    See Also
    SizeOf(object)
    ShallowSizeOf(object)
    ShallowSizeOfInstance(Type)

    SizeOf(uint[])

    Returns the size in bytes of the uint[] object.

    Declaration
    [CLSCompliant(false)]
    public static long SizeOf(uint[] arr)
    Parameters
    Type Name Description
    uint[] arr
    Returns
    Type Description
    long
    See Also
    SizeOf(object)
    ShallowSizeOf(object)
    ShallowSizeOfInstance(Type)

    SizeOf(ulong[])

    Returns the size in bytes of the ulong[] object.

    Declaration
    [CLSCompliant(false)]
    public static long SizeOf(ulong[] arr)
    Parameters
    Type Name Description
    ulong[] arr
    Returns
    Type Description
    long
    See Also
    SizeOf(object)
    ShallowSizeOf(object)
    ShallowSizeOfInstance(Type)

    See Also

    SizeOf(object)
    ShallowSizeOf(object)
    ShallowSizeOfInstance(Type)
    Back to top Copyright © 2024 The Apache Software Foundation, Licensed under the Apache License, Version 2.0
    Apache Lucene.Net, Lucene.Net, Apache, the Apache feather logo, and the Apache Lucene.Net project logo are trademarks of The Apache Software Foundation.
    All other marks mentioned may be trademarks or registered trademarks of their respective owners.