Windows implements the memory file mapping, Golang is actually called the Windows API, and Win32 programming no GOD horse difference.
FD, Err: = Syscall. Open ("./111.csv", Syscall. Generic_all, 0)
Defer syscall. Close (FD)
Fsize, err: = Syscall. Seek (FD, 0, 2)
Syscall. Seek (FD, 0, 0)
Number of pages per block
var pagesperblock int64 = 8192
Number of data blocks
var blocksize int64 = Int64 (Syscall. GetPageSize ()) * Pagesperblock
var blocknum int64 = Fsize/blocksize
If fsize%blocksize > 0 {
Blocknum = blocknum + 1
}
Hmap, err: = Syscall. CreateFileMapping (FD, Nil, syscall. Page_readonly, UInt32 (fsize>>32), UInt32 (fsize), nil)
Defer syscall. CloseHandle (HMAP)
var tmbgn = time. Now ()
Fmt. Println ("blocknum=", Blocknum)
var i int64
For i = 0; i < Blocknum; i++ {
var datalen int32 = Int32 (BlockSize)
if i = = (blocknum-1) {
Datalen = Int32 (fsize% blocksize)
}
Fmt. Println ("datalen=", Datalen)
Start reading memory block
var Currpos int64 = i * blocksize
var Tmplen int = int (datalen)
Addr, err: = Syscall. MapViewOfFile (Hmap, Syscall. File_map_read, 0, UInt32 (currpos), UIntPtr (Tmplen))
Defer syscall. UnmapViewOfFile (addr)
Turn addr into slice.
D: = (*[1 << 28]byte) (unsafe. Pointer (addr))
T: = D[:tmplen]
Processing Data T
}
Golang Windows Memory File mapping