Skip to content

Instantly share code, notes, and snippets.

@alexyakunin
Created July 31, 2019 23:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexyakunin/b34fa184bb1fd574697ee8e2d731f39d to your computer and use it in GitHub Desktop.
Save alexyakunin/b34fa184bb1fd574697ee8e2d731f39d to your computer and use it in GitHub Desktop.
public static long ComputeSumMMF(string fileName,
Func<IntPtr, long, long, int, (long, int)> sumComputer)
{
using var f = MemoryMappedFile.CreateFromFile(fileName, FileMode.Open);
using var fAccessor = f.CreateViewAccessor();
var fHandle = fAccessor.SafeMemoryMappedViewHandle;
var (sum, _) = sumComputer(fHandle.DangerousGetHandle(), (long) fHandle.ByteLength, 0, 0);
return sum;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment