[interprocess] file_mapping/mapped_region on empty file throws?

The following appears to throw an interprocess_exception with boost_1_44_0 compiled with MSVC8 running on windows XP. using namespace boost::interprocess; file_mapping fm("empty.txt", read_only); mapped_region mr( fm, read_only); Is there a reason I can't just get back a null address and zero size? I've wrapped this to get back a begin/end range and an empty range is a valid condition. Thanks, Jeff

On 29/11/2010 19:05, Jeff Flinn wrote:
The following appears to throw an interprocess_exception with boost_1_44_0 compiled with MSVC8 running on windows XP.
using namespace boost::interprocess;
file_mapping fm("empty.txt", read_only); mapped_region mr( fm, read_only);
Is there a reason I can't just get back a null address and zero size?
It's common practice not to support empty mappings. Windows mapped files don't support an empty file. In Unix, mapping zero bytes is an error: http://www.opengroup.org/onlinepubs/009695399/functions/mmap.html "If len is zero, mmap() shall fail and no mapping shall be established" Ion

Ion Gaztañaga wrote:
On 29/11/2010 19:05, Jeff Flinn wrote:
The following appears to throw an interprocess_exception with boost_1_44_0 compiled with MSVC8 running on windows XP.
using namespace boost::interprocess;
file_mapping fm("empty.txt", read_only); mapped_region mr( fm, read_only);
Is there a reason I can't just get back a null address and zero size?
It's common practice not to support empty mappings. Windows mapped files don't support an empty file. In Unix, mapping zero bytes is an error:
http://www.opengroup.org/onlinepubs/009695399/functions/mmap.html
"If len is zero, mmap() shall fail and no mapping shall be established"
Thanks Ion. I'll just deal with the exception appropriately then. Jeff
participants (2)
-
Ion Gaztañaga
-
Jeff Flinn