Exemple #1
0
        public Stream MapView(MapAccess access, long offset, IntPtr size)
        {
            if (!IsOpen)
            {
                throw new ObjectDisposedException("MMF already closed");
            }

            IntPtr baseAddress = IntPtr.Zero;

            baseAddress = Win32MapApis.MapViewOfFile(
                _hMap, (int)access,
                (int)((offset >> 32) & 0xFFFFFFFF),
                (int)(offset & 0xFFFFFFFF), size
                );

            if (baseAddress == IntPtr.Zero)
            {
                throw new FileMapIOException(Marshal.GetHRForLastWin32Error());
            }

            // Find out what MapProtection to use
            // based on the MapAccess flags...
            MapProtection protection;

            if (access == MapAccess.FileMapRead)
            {
                protection = MapProtection.PageReadOnly;
            }
            else
            {
                protection = MapProtection.PageReadWrite;
            }

            return(new MapViewStream(baseAddress, size.ToInt64(), protection));
        }
Exemple #2
0
        public IntPtr MapView(MapAccess access, long offset, long size)
        {
            if (!IsOpen)
            {
                throw new ObjectDisposedException("Winterdom.IO.FileMap.MemoryMappedFile.MapView - MMF already closed");
            }

            // Throws OverflowException if (a) this is a 32-bit platform AND (b) size is out of bounds (ie. int bounds) with respect to this platform
            IntPtr mapSize = new IntPtr(size);

            IntPtr baseAddress = Win32MapApis.MapViewOfFile(
                _hMap, (int)access,
                (int)((offset >> 32) & 0xFFFFFFFF),
                (int)(offset & 0xFFFFFFFF), mapSize
                );

            if (baseAddress == IntPtr.Zero)
            {
                throw new FileMapIOException(Marshal.GetHRForLastWin32Error());
            }

            return(baseAddress);
        }