Boost logo

Boost :

From: Malte Starostik (malte_at_[hidden])
Date: 2002-10-09 16:14:04

On Wednesday 09 October 2002 22:14, Craig Henderson wrote:
> I have a generic (wrt data) class to manage and provide access to a memory
> mapped file on Windows using the Win32 API and with gcc (on cygwin) using
> the POSIX functions mmap() and munmap(). The POSIX should recompile to
> other platforms with gcc without modification. Is there any interest in
> adding such a class to the Boost library? I think it would be a nice
> complimentary class for the filesystem library.
Yes I'd be interested.

> begin 666 mapmem.hpp
Args, okay, copying snippets after manually decoding :-)

> namespace memory_mapped_file {
> } // namespace memory_mapped_file

> template <typename T>
> class memory_mapped_file
> {
IIRC some compilers have problems with this. Might be safer to rename the

(POSIX case)
> #elif defined(BOOST_HAS_POSIX_MMAP)
> typedef int memmap_file;
> typedef int protection;
> typedef int flags_or_security;
> typedef int max_len;
> typedef int offset;
please consider off_t (from sys/types.h) for max_len and offset on POSIX as it
allows for 64-bit use.

> typedef enum { readonly, readwrite } open_access;
In some cases, writeonly access makes sense as well (e.g. shared memory)

> public:
> memory_mapped_file();
> memory_mapped_file(memory_mapped_file::memmap_file &handle,
open_access access);
> ~memory_mapped_file();

> bool map_readonly(memory_mapped_file::memmap_file &handle);
> bool map_readwrite(memory_mapped_file::memmap_file &handle);
Maybe add these?:
        bool map_writeonly(memory_mapped_file::memmap_file &handle); // see above
        memorory_mapped_file(const std::string& file_name, open_access access);
        bool map_readonly(const std::string& file_name);
        bool map_readwrite(const std::string& file_name);
        bool map_writeonly(const std::string& file_name); // see above

> // this is exposed publicly for completeness, but is
> // unlikely to be used by the library user
> bool map(memory_mapped_file::memmap_file &handle,
> memory_mapped_file::protection &prot,
> memory_mapped_file::flags_or_security &fos,
> memory_mapped_file::max_len &len,
> memory_mapped_file::offset &off);
Yes, it's unhandy to use, maybe the ctors and map_XXX() could take an offse
(default 0) and length (default 0 == auto)?


Boost list run by bdawes at, gregod at, cpdaniel at, john at