Opened 11 years ago

Closed 10 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 Marshall Clow)

My email address is

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")

Current code:

        ::SetFilePointer(pimpl_->handle_, sizelow,
&sizehigh, FILE_BEGIN);
        if (::GetLastError() != NO_ERROR ||
            detail::cleanup_and_throw(*pimpl_, "failed
setting file size");

Should be:

        DWORD dwResult =
::SetFilePointer(pimpl_->handle_, sizelow, &sizehigh,
        if (dwResult == INVALID_SET_FILE_POINTER
::GetLastError() != NO_ERROR ||
            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

Attachments (0)

Change History (4)

comment:1 Changed 10 years ago by Marshall Clow

Component: Noneiostreams
Description: modified (diff)
Severity: Problem

comment:2 Changed 10 years ago by anonymous

Is this a duplicate of Ticket #856

comment:3 Changed 10 years ago by Jonathan Turkanis

this is not a duplicate of #699; #699 deals with file_descriptor, not mapped_file

comment:4 Changed 10 years ago by Jonathan Turkanis

Resolution: Nonefixed
Status: assignedclosed

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.

Modify Ticket

Change Properties
Set your email in Preferences
as closed The owner will remain Jonathan Turkanis.
The resolution will be deleted.

Add Comment

E-mail address and name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.