Exemplo n.º 1
0
        private unsafe bool TryCreateMemoryMappedFileBlock(long start, int size, out MemoryMappedFileBlock block)
        {
            if (_lazyMemoryMap == null)
            {
                // leave the underlying stream open. It will be closed by the Dispose method.
                IDisposable newMemoryMap;

                // CreateMemoryMap might modify the stream (calls FileStream.Flush)
                lock (_streamGuard)
                {
                    newMemoryMap = MemoryMapLightUp.CreateMemoryMap(_stream);
                }

                if (newMemoryMap == null)
                {
                    block = null;
                    return(false);
                }

                if (Interlocked.CompareExchange(ref _lazyMemoryMap, newMemoryMap, null) != null)
                {
                    newMemoryMap.Dispose();
                }
            }

            IDisposable accessor = MemoryMapLightUp.CreateViewAccessor(_lazyMemoryMap, start, size);

            if (accessor == null)
            {
                block = null;
                return(false);
            }

            SafeBuffer safeBuffer;
            byte *     pointer = MemoryMapLightUp.AcquirePointer(accessor, out safeBuffer);

            if (pointer == null)
            {
                block = null;
                return(false);
            }

            block = new MemoryMappedFileBlock(accessor, safeBuffer, pointer, size);
            return(true);
        }
 internal unsafe MemoryMappedFileBlock(IDisposable accessor, int size)
 {
     this.accessor = accessor;
     this.pointer  = MemoryMapLightUp.AcquirePointer(accessor, out safeBuffer);
     this.size     = size;
 }
Exemplo n.º 3
0
 internal unsafe MemoryMappedFileBlock(IDisposable accessor, int size)
 {
     _accessor = accessor;
     _pointer  = MemoryMapLightUp.AcquirePointer(accessor, out _safeBuffer);
     _size     = size;
 }