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.
Implements
Inherited Members
Namespace: Lucene.Net.Store
Assembly: Lucene.Net.dll
Syntax
public class RAMDirectory : BaseDirectory, IDisposable
Constructors
| Improve this Doc View SourceRAMDirectory()
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 |
---|---|
System.IO.IOException | if an error occurs |
Fields
| Improve this Doc View Sourcem_fileMap
Declaration
protected readonly ConcurrentDictionary<string, RAMFile> m_fileMap
Field Value
Type | Description |
---|---|
System.Collections.Concurrent.ConcurrentDictionary<System.String, RAMFile> |
m_sizeInBytes
Declaration
protected readonly AtomicInt64 m_sizeInBytes
Field Value
Type | Description |
---|---|
J2N.Threading.Atomic.AtomicInt64 |
Methods
| Improve this Doc View SourceCreateOutput(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 |
---|---|---|
System.String | name | |
IOContext | context |
Returns
Type | Description |
---|---|
IndexOutput |
Overrides
| Improve this Doc View SourceDeleteFile(String)
Removes an existing file in the directory.
Declaration
public override void DeleteFile(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name |
Overrides
Exceptions
Type | Condition |
---|---|
System.IO.IOException | if the file does not exist |
Dispose(Boolean)
Closes the store to future operations, releasing associated memory.
Declaration
protected override void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | disposing |
Overrides
| Improve this Doc View SourceFileExists(String)
Returns true iff the named file exists in this directory.
Declaration
[Obsolete("this method will be removed in 5.0")]
public sealed override bool FileExists(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name |
Returns
Type | Description |
---|---|
System.Boolean |
Overrides
| Improve this Doc View SourceFileLength(String)
Returns the length in bytes of a file in the directory.
Declaration
public sealed override long FileLength(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name |
Returns
Type | Description |
---|---|
System.Int64 |
Overrides
Exceptions
Type | Condition |
---|---|
System.IO.IOException | if the file does not exist |
GetLockID()
Declaration
public override string GetLockID()
Returns
Type | Description |
---|---|
System.String |
Overrides
| Improve this Doc View SourceGetSizeInBytes()
Return total size in bytes of all files in this directory. This is currently quantized to Lucene.Net.Store.RAMOutputStream.BUFFER_SIZE.
Declaration
public long GetSizeInBytes()
Returns
Type | Description |
---|---|
System.Int64 |
ListAll()
Declaration
public sealed override string[] ListAll()
Returns
Type | Description |
---|---|
System.String[] |
Overrides
| Improve this Doc View SourceNewRAMFile()
Returns a new RAMFile for storing data. this method can be overridden to return different RAMFile impls, that e.g. override NewBuffer(Int32).
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 |
---|---|---|
System.String | name | |
IOContext | context |
Returns
Type | Description |
---|---|
IndexInput |
Overrides
| Improve this Doc View SourceSync(ICollection<String>)
Declaration
public override void Sync(ICollection<string> names)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.ICollection<System.String> | names |