## org.apache.lucene.util
Class RamUsageEstimator

    java.lang.Object
      org.apache.lucene.util.RamUsageEstimator

    public final class RamUsageEstimator

extends Object

Estimates the size of a given Object using a given MemoryModel for primitive size information. Resource Usage: Internally uses a Map to temporally hold a reference to every object seen. If checkInterned, all Strings checked will be interned, but those that were not already interned will be released for GC when the estimate is complete.

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

Field Summary
`static int` `NUM_BYTES_ARRAY_HEADER`
`static int` `NUM_BYTES_CHAR`
`static int` `NUM_BYTES_DOUBLE`
`static int` `NUM_BYTES_FLOAT`
`static int` `NUM_BYTES_INT`
`static int` `NUM_BYTES_LONG`
`static int` `NUM_BYTES_OBJECT_HEADER`
`static int` `NUM_BYTES_OBJECT_REF`
`static int` `NUM_BYTES_SHORT`

Constructor Summary
`RamUsageEstimator()` Constructs this object with an AverageGuessMemoryModel and checkInterned = true.
`RamUsageEstimator(boolean checkInterned)`
`RamUsageEstimator(MemoryModel memoryModel)`
`RamUsageEstimator(MemoryModel memoryModel, boolean checkInterned)`

Method Summary
`long` `estimateRamUsage(Object obj)`
`static String` `humanReadableUnits(long bytes, DecimalFormat df)` Return good default units based on byte size.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### NUM_BYTES_SHORT

    public static final int NUM_BYTES_SHORT

See Also:
  Constant Field Values

### NUM_BYTES_INT

    public static final int NUM_BYTES_INT

See Also:
  Constant Field Values

### NUM_BYTES_LONG

    public static final int NUM_BYTES_LONG

See Also:
  Constant Field Values

### NUM_BYTES_FLOAT

    public static final int NUM_BYTES_FLOAT

See Also:
  Constant Field Values

### NUM_BYTES_DOUBLE

    public static final int NUM_BYTES_DOUBLE

See Also:
  Constant Field Values

### NUM_BYTES_CHAR

    public static final int NUM_BYTES_CHAR

See Also:
  Constant Field Values

### NUM_BYTES_OBJECT_HEADER

    public static final int NUM_BYTES_OBJECT_HEADER

See Also:
  Constant Field Values

### NUM_BYTES_OBJECT_REF

    public static final int NUM_BYTES_OBJECT_REF

### NUM_BYTES_ARRAY_HEADER

    public static final int NUM_BYTES_ARRAY_HEADER

Constructor Detail

### RamUsageEstimator

    public RamUsageEstimator()

  Constructs this object with an AverageGuessMemoryModel and checkInterned = true.

### RamUsageEstimator

    public RamUsageEstimator(boolean checkInterned)

Parameters:
  `checkInterned` - check if Strings are interned and don't add to size if they are. Defaults to true but if you know the objects you are checking won't likely contain many interned Strings, it will be faster to turn off intern checking.

### RamUsageEstimator

    public RamUsageEstimator(MemoryModel memoryModel)

Parameters:
  `memoryModel` - MemoryModel to use for primitive object sizes.

### RamUsageEstimator

    public RamUsageEstimator(MemoryModel memoryModel,
                             boolean checkInterned)

Parameters:
  `memoryModel` - MemoryModel to use for primitive object sizes.
  `checkInterned` - check if Strings are interned and don't add to size if they are. Defaults to true but if you know the objects you are checking won't likely contain many interned Strings, it will be faster to turn off intern checking.

Method Detail

### estimateRamUsage

    public long estimateRamUsage(Object obj)

### humanReadableUnits

    public static String humanReadableUnits(long bytes,
                                            DecimalFormat df)

  Return good default units based on byte size.

Copyright © 2000-2011 Apache Software Foundation. All Rights Reserved.