Lucene.Net.Store.MMapDirectory.Map C# (CSharp) Method

Map() private method

Maps a file into a set of buffers
private Map ( MMapIndexInput input, FileStream fc, long offset, long length ) : System.ByteBuffer[]
input MMapIndexInput
fc System.IO.FileStream
offset long
length long
return System.ByteBuffer[]
        internal virtual ByteBuffer[] Map(MMapIndexInput input, FileStream fc, long offset, long length)
        {
            if (Number.URShift(length, ChunkSizePower) >= int.MaxValue)
                throw new ArgumentException("RandomAccessFile too big for chunk size: " + fc.ToString());

            long chunkSize = 1L << ChunkSizePower;

            // we always allocate one more buffer, the last one may be a 0 byte one
            int nrBuffers = (int)((long)((ulong)length >> ChunkSizePower)) + 1;

            ByteBuffer[] buffers = new ByteBuffer[nrBuffers];

            /*
             public static MemoryMappedFile CreateFromFile(FileStream fileStream, String mapName, Int64 capacity,
                                                        MemoryMappedFileAccess access, MemoryMappedFileSecurity memoryMappedFileSecurity,
                                                        HandleInheritability inheritability, bool leaveOpen)
             */

            long fileCapacity = length == 0 ? ushort.MaxValue : length;

            if (input.memoryMappedFile == null)
            {
                input.memoryMappedFile = MemoryMappedFile.CreateFromFile(fc, null, fileCapacity, MemoryMappedFileAccess.ReadWrite, null, HandleInheritability.Inheritable, false);
            }

            long bufferStart = 0L;
            for (int bufNr = 0; bufNr < nrBuffers; bufNr++)
            {
                int bufSize = (int)((length > (bufferStart + chunkSize)) ? chunkSize : (length - bufferStart));

                // LUCENENET: We get a file access exception if we create a 0 byte file at the end of the range.
                // We can fix this by moving back 1 byte if the bufSize is 0.
                int adjust = 0;
                if (bufSize == 0 && bufNr == (nrBuffers - 1) && (offset + bufferStart) > 0)
                {
                    adjust = 1;
                }

                buffers[bufNr] = new MemoryMappedFileByteBuffer(input.memoryMappedFile.CreateViewAccessor((offset + bufferStart) - adjust, bufSize, MemoryMappedFileAccess.Read), -1, 0, bufSize, bufSize);
                bufferStart += bufSize;
            }

            return buffers;
        }
    }

Usage Example

示例#1
0
 internal MMapIndexInput(MMapDirectory outerInstance, string resourceDescription, FileStream fc)
     : base(resourceDescription, null, fc.Length, outerInstance.chunkSizePower, true)
 {
     this.outerInstance = outerInstance;
     this.fc            = fc ?? throw new ArgumentNullException("fc");
     this.SetBuffers(outerInstance.Map(this, fc, 0, fc.Length));
 }
All Usage Examples Of Lucene.Net.Store.MMapDirectory::Map