Fix closeHandle bug, add setFileSize, make resize work on Windows (#21375)
* Add general purpose `setFileSize` (unexported for now). Use to simplify `memfiles.open` as well as make robust (via hard allocation, not merely `ftruncate` address space allocation) on systems with `posix_fallocate`. As part of this, fix a bad `closeHandle` return check bug on Windows and add `MemFile.resize` for Windows now that setFileSize makes that easier. * Adapt existing test to exercise newly portable `MemFile.resize`. * Since Apple has never provided `posix_fallocate`, provide a fallback. This is presently written in terms of `ftruncate`, but it can be improved to use `F_PREALLOCATE` instead, as mentioned in a comment.
This commit is contained in:
parent
e24d0e5faf
commit
c91ef1a09f
3 changed files with 92 additions and 47 deletions
|
|
@ -15,8 +15,9 @@ var
|
|||
|
||||
if fileExists(fn): removeFile(fn)
|
||||
|
||||
# Create a new file, data all zeros
|
||||
mm = memfiles.open(fn, mode = fmReadWrite, newFileSize = 20)
|
||||
# Create a new file, data all zeros, starting at size 10
|
||||
mm = memfiles.open(fn, mode = fmReadWrite, newFileSize = 10, allowRemap=true)
|
||||
mm.resize 20 # resize up to 20
|
||||
mm.close()
|
||||
|
||||
# read, change
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue