Fork me on GitHub
  • API

    Show / Hide Table of Contents

    Class RAMDirectory

    A memory-resident Directory implementation. Locking implementation is by default the SingleInstanceLockFactory but can be changed with SetLockFactory(LockFactory).

    Warning: This class is not intended to work with huge indexes. Everything beyond several hundred megabytes will waste resources (GC cycles), because it uses an internal buffer size of 1024 bytes, producing millions of byte[1024] arrays. This class is optimized for small memory-resident indexes. It also has bad concurrency on multithreaded environments.

    It is recommended to materialize large indexes on disk and use MMapDirectory, which is a high-performance directory implementation working directly on the file system cache of the operating system, so copying data to heap space is not useful.
    Inheritance
    object
    Directory
    BaseDirectory
    RAMDirectory
    Implements
    IDisposable
    Inherited Members
    BaseDirectory.IsOpen
    BaseDirectory.CompareAndSetIsOpen(bool, bool)
    BaseDirectory.m_lockFactory
    BaseDirectory.MakeLock(string)
    BaseDirectory.ClearLock(string)
    BaseDirectory.SetLockFactory(LockFactory)
    BaseDirectory.LockFactory
    BaseDirectory.EnsureOpen()
    Directory.OpenChecksumInput(string, IOContext)
    Directory.Dispose()
    Directory.ToString()
    Directory.Copy(Directory, string, string, IOContext)
    Directory.CreateSlicer(string, IOContext)
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    Namespace: Lucene.Net.Store
    Assembly: Lucene.Net.dll
    Syntax
    public class RAMDirectory : BaseDirectory, IDisposable

    Constructors

    RAMDirectory()

    Constructs an empty Directory.

    Declaration
    public RAMDirectory()

    RAMDirectory(Directory, IOContext)

    Creates a new RAMDirectory instance from a different Directory implementation. This can be used to load a disk-based index into memory.

    Warning: this class is not intended to work with huge indexes. Everything beyond several hundred megabytes will waste resources (GC cycles), because it uses an internal buffer size of 1024 bytes, producing millions of byte[1024] arrays. this class is optimized for small memory-resident indexes. It also has bad concurrency on multithreaded environments.

    For disk-based indexes it is recommended to use MMapDirectory, which is a high-performance directory implementation working directly on the file system cache of the operating system, so copying data to heap space is not useful.

    Note that the resulting RAMDirectory instance is fully independent from the original Directory (it is a complete copy). Any subsequent changes to the original Directory will not be visible in the RAMDirectory instance.
    Declaration
    public RAMDirectory(Directory dir, IOContext context)
    Parameters
    Type Name Description
    Directory dir

    a Directory value

    IOContext context

    io context

    Exceptions
    Type Condition
    IOException

    if an error occurs

    Fields

    m_fileMap

    A memory-resident Directory implementation. Locking implementation is by default the SingleInstanceLockFactory but can be changed with SetLockFactory(LockFactory).

    Warning: This class is not intended to work with huge indexes. Everything beyond several hundred megabytes will waste resources (GC cycles), because it uses an internal buffer size of 1024 bytes, producing millions of byte[1024] arrays. This class is optimized for small memory-resident indexes. It also has bad concurrency on multithreaded environments.

    It is recommended to materialize large indexes on disk and use MMapDirectory, which is a high-performance directory implementation working directly on the file system cache of the operating system, so copying data to heap space is not useful.
    Declaration
    protected readonly ConcurrentDictionary<string, RAMFile> m_fileMap
    Field Value
    Type Description
    ConcurrentDictionary<string, RAMFile>

    m_sizeInBytes

    A memory-resident Directory implementation. Locking implementation is by default the SingleInstanceLockFactory but can be changed with SetLockFactory(LockFactory).

    Warning: This class is not intended to work with huge indexes. Everything beyond several hundred megabytes will waste resources (GC cycles), because it uses an internal buffer size of 1024 bytes, producing millions of byte[1024] arrays. This class is optimized for small memory-resident indexes. It also has bad concurrency on multithreaded environments.

    It is recommended to materialize large indexes on disk and use MMapDirectory, which is a high-performance directory implementation working directly on the file system cache of the operating system, so copying data to heap space is not useful.
    Declaration
    protected readonly AtomicInt64 m_sizeInBytes
    Field Value
    Type Description
    AtomicInt64

    Methods

    CreateOutput(string, IOContext)

    Creates a new, empty file in the directory with the given name. Returns a stream writing this file.

    Declaration
    public override IndexOutput CreateOutput(string name, IOContext context)
    Parameters
    Type Name Description
    string name
    IOContext context
    Returns
    Type Description
    IndexOutput
    Overrides
    Directory.CreateOutput(string, IOContext)

    DeleteFile(string)

    Removes an existing file in the directory.

    Declaration
    public override void DeleteFile(string name)
    Parameters
    Type Name Description
    string name
    Overrides
    Directory.DeleteFile(string)
    Exceptions
    Type Condition
    IOException

    if the file does not exist

    Dispose(bool)

    Closes the store to future operations, releasing associated memory.

    Declaration
    protected override void Dispose(bool disposing)
    Parameters
    Type Name Description
    bool disposing
    Overrides
    Directory.Dispose(bool)

    FileExists(string)

    Returns true iff the named file exists in this directory.

    Declaration
    [Obsolete("this method will be removed in 5.0")]
    public override sealed bool FileExists(string name)
    Parameters
    Type Name Description
    string name
    Returns
    Type Description
    bool
    Overrides
    Directory.FileExists(string)

    FileLength(string)

    Returns the length in bytes of a file in the directory.

    Declaration
    public override sealed long FileLength(string name)
    Parameters
    Type Name Description
    string name
    Returns
    Type Description
    long
    Overrides
    Directory.FileLength(string)
    Exceptions
    Type Condition
    IOException

    if the file does not exist

    GetLockID()

    Return a string identifier that uniquely differentiates this Directory instance from other Directory instances. This ID should be the same if two Directory instances (even in different AppDomains and/or on different machines) are considered "the same index". This is how locking "scopes" to the right index.

    Declaration
    public override string GetLockID()
    Returns
    Type Description
    string
    Overrides
    Directory.GetLockID()

    GetSizeInBytes()

    Return total size in bytes of all files in this directory. This is currently quantized to BUFFER_SIZE.

    Declaration
    public long GetSizeInBytes()
    Returns
    Type Description
    long

    ListAll()

    Returns an array of strings, one for each file in the directory.

    Declaration
    public override sealed string[] ListAll()
    Returns
    Type Description
    string[]
    Overrides
    Directory.ListAll()
    Exceptions
    Type Condition
    DirectoryNotFoundException

    if the directory is not prepared for any write operations (such as CreateOutput(string, IOContext)).

    IOException

    in case of other IO errors

    NewRAMFile()

    Returns a new RAMFile for storing data. this method can be overridden to return different RAMFile impls, that e.g. override NewBuffer(int).

    Declaration
    protected virtual RAMFile NewRAMFile()
    Returns
    Type Description
    RAMFile

    OpenInput(string, IOContext)

    Returns a stream reading an existing file.

    Declaration
    public override IndexInput OpenInput(string name, IOContext context)
    Parameters
    Type Name Description
    string name
    IOContext context
    Returns
    Type Description
    IndexInput
    Overrides
    Directory.OpenInput(string, IOContext)

    Sync(ICollection<string>)

    Ensure that any writes to these files are moved to stable storage. Lucene uses this to properly commit changes to the index, to prevent a machine/OS crash from corrupting the index.

    NOTE: Clients may call this method for same files over and over again, so some impls might optimize for that. For other impls the operation can be a noop, for various reasons.

    Declaration
    public override void Sync(ICollection<string> names)
    Parameters
    Type Name Description
    ICollection<string> names
    Overrides
    Directory.Sync(ICollection<string>)

    Implements

    IDisposable
    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.