Example #1
0
        /// <summary>
        /// Build a MappedFile object. The file is open in sharing.
        /// </summary>
        /// <param name="path">Path to the file</param>
        public MappedFile(string path)
        {
            FileStream f = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);

            len = (int)f.Length;
            fm  = new FileMap(f);
            f.Close(); // Not needed anymore: the handle has been duplicated
            mv    = new MapView(fm, 0, len);
            start = mv.GetPointer();
        }
Example #2
0
        /// <summary>
        /// Builds a mapped view of a mapped file.
        /// </summary>
        /// <param name="m">File mapping to use</param>
        /// <param name="off">Offset to be mapped</param>
        /// <param name="sz">Size of the view</param>
        public MapView(FileMap m, long off, int sz)
        {
            long basep = off & Win32Mapping.MaskOffset;
            int  gap   = (int)(off & Win32Mapping.MaskBase);

            unsafe {
                addr = (byte *)Win32Mapping.MapViewOfFile(m.Handle,
                                                          FileMapAccess.FILE_MAP_READ, (int)(basep >> 32),
                                                          (int)(basep & 0xFFFFFFFFL), sz);
                pb   = addr + gap;
                size = sz;
            }
        }