Boost logo

Boost :

From: Jonathan Turkanis (technews_at_[hidden])
Date: 2004-08-31 23:11:25


"Jonathan Graehl" <jonathan_at_[hidden]> wrote in message
news:413535B2.5090105_at_graehl.org...
> Generally: four stars, two thumbs up, and a partridge in a pear tree.

Thanks.

> I'm interested in directly using the Windows/POSIX mmap portability
> wrapper; might we promote it out of the detail namespace? That is, I
> may want to use mmap to perform some explicit memory swapping/caching.

Yes. I discussed this with Craig Henderson, the original author of Boost.Memmap
in the sandbox. Since I ran out of time to document memmap.hpp, I left it as an
implementation detail, with the idea that it might be a good candidate for fast
track review later.

----
Here's a brief description of the interface of detail::mapped_file and
detail::readonly_mapped_file:
Both have a std::fstream-like interface, consiting of member functions
open()/is_open()/close() and 'opening' constuctors which take the same
parameters as open(). A safe-bool conversion and operator! can be used
equivalently to is_open() to tell whether the file has been opened and mapped
successfully.
They also have a std::string-like interface consisting of member functions
begin(), end(), data() and size(). (Obviously there is some redundancy here.)
detail::mapped_file can be opened in read-only mode; to faciliate this it also
has members const_begin(), const_end() and const_data().
There's also a static member alignment() returning the allocation granularity
for virtual memory.
Both are non-copyable.
----
> It looks like I could first create a file of the desired size, then
> acquire a mapped_file_resource - but then I don't get access to the
> actual pointer to memory (it's hidden in the private _pimpl).  This is
> fine; what I really want is a portability wrapper for mmap :)
You can get the actual pointer using the functions input_sequence or
output_sequence (part of the Direct Resource interface) which return standard
pairs of pointers.
    mapped_file_resource file("hello.txt");
    std::pair<char*, char*> seq = file.input_sequence();
    char* ptr = seq.first;
    size_t size = seq.second - seq.first;
Hope this helps.
Jonathan

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk