日期:2014-05-18 浏览次数:21179 次
long fileSize = 3<<30;//3G 3G/8M=384,3G%8M=0 uint blockBytes = 1<<23;//8M 8M/64K=128,8M%64K=0,64K为系统页分配粒度 long fileOffset = 0; byte[] temp = new byte[blockBytes]; while(fileSize-fileOffset>0) { IntPtr hMapView = MapViewOfFile(hMapping, FILE_MAP_COPY | FILE_MAP_READ | FILE_MAP_WRITE, (uint)(fileOffset >> 32), (uint)(fileOffset & 0xFFFFFFFF), blockBytes); if (hMapView == IntPtr.Zero) { throw new Exception(Marshal.GetLastWin32Error().ToString()); } Marshal.Copy(hMapView, temp, 0, (int)blockBytes); fileOffset += blockBytes; UnmapViewOfFile(hMapView); }