Opened 16 years ago
Closed 15 years ago
#699 closed Bugs (fixed)
Changing size of memory-mapped file on Windows
| Reported by: | nobody | Owned by: | Jonathan Turkanis |
|---|---|---|---|
| Milestone: | Component: | iostreams | |
| Version: | None | Severity: | Problem |
| Keywords: | Cc: |
Description (last modified by )
My email address is barrywhart@yahoo.com.
There is a bug in
mapped_file_source::open_impl(mapped_file_params p)
This function does not correctly check for errors from
SetFilePointer, as documented in the MSDN page below.
(See "Case Two: calling the function with
lpDistanceToMoveHigh != NULL")
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/setfilepointer.asp
Current code:
::SetFilePointer(pimpl_->handle_, sizelow,
&sizehigh, FILE_BEGIN);
if (::GetLastError() != NO_ERROR ||
!::SetEndOfFile(pimpl_->handle_))
detail::cleanup_and_throw(*pimpl_, "failed
setting file size");
Should be:
DWORD dwResult =
::SetFilePointer(pimpl_->handle_, sizelow, &sizehigh,
FILE_BEGIN);
if (dwResult == INVALID_SET_FILE_POINTER
::GetLastError() != NO_ERROR ||
!::SetEndOfFile(pimpl_->handle_))
detail::cleanup_and_throw(*pimpl_, "failed
setting file size");
--
Even after this fix, the ability to resize an existing
file is not really useful because the file is
apparently recreated rather than resized. I am working
around this by resizing the file using system calls,
but I wonder if this is how the function is supposed to
work?!
Change History (4)
comment:1 by , 15 years ago
| Component: | None → iostreams |
|---|---|
| Description: | modified (diff) |
| Severity: | → Problem |
comment:2 by , 15 years ago
comment:3 by , 15 years ago
comment:4 by , 15 years ago
| Resolution: | None → fixed |
|---|---|
| Status: | assigned → closed |
Fixed use of SetFilePointer in [42353] in branches/iostreams_dev, to be merged with trunk shortly.
Regarding the ability to resize an existing file, this is anot a supported feature. The new_file_size property of mapped_file_param is just a way to create a new file of a specified size.
I realize that this is an old ticket, so you may not be interested in the issue anymore; however, if you would like to submit a feature request, I will consider it for 1.36. My initial feeling is that it should be a general file-resizing function, not limited to memory-mapped files; in that case, it would probably be best o put it in Boost.Filesystem.

Is this a duplicate of Ticket #856