mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-02 03:02:31 +00:00
Do not automatically use MAP_POPULATE for opening mmap files.
Adds use_map_populate keyword to memfiles.open and memfiles.mapMem to govern MAP_POPULATE use. This is set to false by default.
This commit is contained in:
@@ -30,14 +30,17 @@ type
|
||||
|
||||
when defined(windows):
|
||||
fHandle: int
|
||||
mapHandle: int
|
||||
mapHandle: int
|
||||
else:
|
||||
handle: cint
|
||||
|
||||
|
||||
proc mapMem*(m: var TMemFile, mode: TFileMode = fmRead,
|
||||
mappedSize = -1, offset = 0): pointer =
|
||||
mappedSize = -1, offset = 0,
|
||||
use_map_populate = false): pointer =
|
||||
var readonly = mode == fmRead
|
||||
if not use_map_populate:
|
||||
MAP_POPULATE = 0
|
||||
when defined(windows):
|
||||
result = mapViewOfFileEx(
|
||||
m.mapHandle,
|
||||
@@ -72,7 +75,8 @@ proc unmapMem*(f: var TMemFile, p: pointer, size: int) =
|
||||
|
||||
|
||||
proc open*(filename: string, mode: TFileMode = fmRead,
|
||||
mappedSize = -1, offset = 0, newFileSize = -1): TMemFile =
|
||||
mappedSize = -1, offset = 0, newFileSize = -1,
|
||||
use_map_populate = false): TMemFile =
|
||||
## opens a memory mapped file. If this fails, ``EOS`` is raised.
|
||||
## `newFileSize` can only be set if the file does not exist and is opened
|
||||
## with write access (e.g., with fmReadWrite). `mappedSize` and `offset`
|
||||
@@ -94,6 +98,8 @@ proc open*(filename: string, mode: TFileMode = fmRead,
|
||||
# The file can be resized only when write mode is used:
|
||||
assert newFileSize == -1 or mode != fmRead
|
||||
var readonly = mode == fmRead
|
||||
if not use_map_populate:
|
||||
MAP_POPULATE = 0
|
||||
|
||||
template rollback =
|
||||
result.mem = nil
|
||||
|
||||
Reference in New Issue
Block a user