1 <!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN">
4 <TITLE>Memory-Mapped Files
</TITLE>
5 <LINK REL=
"stylesheet" HREF=
"../../../../boost.css">
6 <LINK REL=
"stylesheet" HREF=
"../theme/iostreams.css">
12 <H1 CLASS=
"title">Memory-Mapped Files
</H1>
17 <DL class=
"page-index">
18 <DT><A href=
"#overview">Overview
</A></DT>
19 <DT><A href=
"#acknowledgments">Acknowledgments
</A></DT>
20 <DT><A href=
"#installation">Installation
</A></DT>
21 <DT><A href=
"#headers">Headers
</A></DT>
22 <DT><A href=
"#reference">Reference
</A>
24 <LI CLASS=
"square"><A href=
"#mapped_file_params">Class
<CODE>mapped_file_params
</CODE></A></LI>
25 <LI CLASS=
"square"><A href=
"#mapped_file_source">Class
<CODE>mapped_file_source
</CODE></A></LI>
26 <LI CLASS=
"square"><A href=
"#mapped_file_sink">Class
<CODE>mapped_file_sink
</CODE></A></LI>
27 <LI CLASS=
"square"><A href=
"#mapped_file">Class
<CODE>mapped_file
</CODE></A></LI>
34 <A NAME=
"overview"></A>
38 The classes
<CODE>mapped_file_source
</CODE>,
<CODE>mapped_file_sink
</CODE> and
<CODE>mapped_file
</CODE> provide access to memory-mapped files on Windows and POSIX systems. These
<A HREF=
"../guide/concepts.html#device_concepts">Devices
</A> behave much like the
<A HREF=
"file.html">File Wrappers
</A> <CODE>basic_file_source
</CODE>,
<CODE>basic_file_sink
</CODE> and
<CODE>basic_file
</CODE>, with the following important differences:
41 <LI CLASS=
"square">By default, files must exist before being opened, and are not truncated; attempting to write past the end of a file results in an error. To map a file which does not yet exist, use
<A HREF=
"#mapped_file_params_size"><CODE>mapped_file_params::new_file_size
</CODE></A>.
42 <LI CLASS=
"square">Files are always opened in binary mode.
43 <LI CLASS=
"square">Wide-character streams are not supported.
46 Wide-character versions of the memory-mapped file Devices may be defined as follows, using the template
<A HREF=
"code_converter.html"><CODE>code_converter
</CODE></A>:
47 <PRE CLASS=
"broken_ie"> <SPAN CLASS=
"preprocessor">#include
</SPAN> <A CLASS=
"header" HREF=
"../../../../boost/iostreams/code_converter.hpp"><SPAN CLASS=
"literal"><boost/iostreams/code_converter.hpp
></SPAN></A>
48 <SPAN CLASS=
"preprocessor">#include
</SPAN> <A CLASS=
"header" HREF=
"../../../../boost/iostreams/device/mapped_file.hpp"><SPAN CLASS=
"literal"><boost/iostreams/device/mapped_file.hpp
></SPAN></A>
50 <SPAN CLASS=
"keyword">typedef
</SPAN> code_converter
<mapped_file_source
> <SPAN CLASS=
"defined">wmapped_file_source
</SPAN>;
51 <SPAN CLASS=
"keyword">typedef
</SPAN> code_converter
<mapped_file_sink
> <SPAN CLASS=
"defined">wmapped_file_sink
</SPAN>;
</PRE>
54 <A NAME=
"acknowledgments"></A>
55 <H2>Acknowledgments
</H2>
58 The memory-mapped file Devices are based on the work of Craig Henderson (
<A CLASS=
"bib_ref" HREF=
"../bibliography.html#henderson">[Henderson]
</A>). Additionals features were implemented by Jonathan Graehl.
61 <A NAME=
"installation"></A>
65 The memory-mapped file Devices depend on the source file
<A CLASS=
"header" HREF=
"../../src/mapped_file.cpp"><CODE><libs/iostreams/src/mapped_file.cpp
></CODE></A>. This source file makes use of Windows or POSIX headers depending on the user's operating system. For installation instructions see
<A HREF=
"../installation.html">Installation
</A>.
68 <A NAME=
"headers"></A>
71 <DL class=
"page-index">
72 <DT><A CLASS=
"header" HREF=
"../../../../boost/iostreams/device/mapped_file.hpp"><CODE><boost/iostreams/device/mapped_file.hpp
></CODE></A></DT>
75 <A NAME=
"reference"></A>
78 <A NAME=
"mapped_file_params"></A>
79 <H3>1. Class
<CODE>mapped_file_params
</CODE></H3>
83 <P>Class encapsulating the parameters used to open a memory-mapped file.
</P>
87 <PRE CLASS=
"broken_ie"><SPAN CLASS=
"keyword">namespace
</SPAN> boost {
<SPAN CLASS=
"keyword">namespace
</SPAN> iostreams {
89 <SPAN CLASS=
"keyword">struct
</SPAN> <SPAN CLASS=
"defined">mapped_file_params
</SPAN> {
90 <SPAN CLASS='keyword'
>explicit
</SPAN> mapped_file_params();
91 <SPAN CLASS='keyword'
>explicit
</SPAN> mapped_file_params(
<SPAN CLASS='keyword'
>const
</SPAN> std::string
& path);
92 std::string
<A CLASS='documented' HREF='#mapped_file_params_hint'
>path
</A>;
93 mapped_file::mapmode
<A CLASS='documented' HREF='#mapped_file_params_flags'
>flags
</A>;
94 std::ios_base::openmode
<A CLASS='documented' HREF='#mapped_file_params_mode'
>mode
</A>; // Deprecated
95 stream_offset
<A CLASS='documented' HREF='#mapped_file_params_offset'
>offset
</A>;
96 std::size_t
<A CLASS='documented' HREF='#mapped_file_params_length'
>length
</A>;
97 stream_offset
<A CLASS=
"documented" HREF=
"#mapped_file_params_size">new_file_size
</A>;
98 <SPAN CLASS='keyword'
>const
</SPAN> <SPAN CLASS='keyword'
>char
</SPAN>*
<A CLASS='documented' HREF='#mapped_file_params_hint'
>hint
</A>;
101 } } // End namespace boost::io
</PRE>
103 <A NAME=
"mapped_file_params_path"></A>
104 <H4><CODE>mapped_file_params::path
</CODE></H4>
106 <PRE CLASS=
"broken_ie"> std::string path;
</PRE>
108 <P>The pathname of the file to map.
</P>
110 <A NAME=
"mapped_file_params_mode"></A>
111 <H4><CODE>mapped_file_params::mode
</CODE></H4>
113 <PRE CLASS=
"broken_ie"> std::ios_base::openmode mode;
</PRE>
115 <P>Indicates whether the file should be opened with read-access, write-access or both. Ignored by
<CODE>mapped_file_source
</CODE> and
<CODE>mapped_file_sink
</CODE>. This member is deprecated. Please use flags in new code instead.
</P>
117 <A NAME=
"mapped_file_params_flags"></A>
118 <H4><CODE>mapped_file_params::flags
</CODE></H4>
120 <PRE CLASS=
"broken_ie"> mapped_file::mapmode flags;
</PRE>
122 <P>Indicates whether the file should be opened with read-access, read-write-access, or private access. A file opened with private access can be written to, but the changes will not affect the underlying file.
</P>
124 <A NAME=
"mapped_file_params_offset"></A>
125 <H4><CODE>mapped_file_params::offset
</CODE></H4>
127 <PRE CLASS=
"broken_ie"> stream_offset offset;
</PRE>
129 <P>The offset where the mapping is to begin. This value must be a multiple of the operating system's virtual memory allocation granularity, which can be abotained via the static member function
<A HREF=
"#mapped_file_alignment"><CODE>alignment
</CODE></A> of
<CODE>mapped_file_source
</CODE>,
<CODE>mapped_file_sink
</CODE> or
<CODE>mapped_file
</CODE>. Defaults to
<CODE>0</CODE>.
</P>
131 <A NAME=
"mapped_file_params_length"></A>
132 <H4><CODE>mapped_file_params::length
</CODE></H4>
134 <PRE CLASS=
"broken_ie"> std::size_t length;
</PRE>
136 <P>The number of bytes to map. If this parameter is not specified, the entire file is mapped.
</P>
138 <A NAME=
"mapped_file_params_size"></A>
139 <H4><CODE>mapped_file_params::new_file_size
</CODE></H4>
141 <PRE CLASS=
"broken_ie"> stream_offset new_file_size;
</PRE>
143 <P>If this value is non-zero it specifies the size of a file to be created. If a file with pathname
<I>path
</I> already exists, it will be overwritten.
</P>
145 <A NAME=
"mapped_file_params_hint"></A>
146 <H4><CODE>mapped_file_params::hint
</CODE></H4>
148 <PRE CLASS=
"broken_ie"> <SPAN CLASS='keyword'
>const
</SPAN> <SPAN CLASS='keyword'
>char
</SPAN>* hint;
</PRE>
150 <P>Suggests a location in the process's address space for the mapping to begin.
</P>
152 <A NAME=
"mapped_file_source"></A>
153 <H3>2. Class
<CODE>mapped_file_source
</CODE></H3>
157 <P>Model of
<A HREF=
"../concepts/source.html">Source
</A> providing read-only access to memory-mapped files on Windows and POSIX systems.
</P>
161 <PRE CLASS=
"broken_ie"><SPAN CLASS=
"keyword">namespace
</SPAN> boost {
<SPAN CLASS=
"keyword">namespace
</SPAN> iostreams {
163 <SPAN CLASS=
"keyword">class
</SPAN> <SPAN CLASS=
"defined">mapped_file_source
</SPAN> {
164 <SPAN CLASS=
"keyword">public
</SPAN>:
165 <SPAN CLASS='keyword'
>typedef
</SPAN> <SPAN CLASS='keyword'
>char
</SPAN> char_type;
166 <SPAN CLASS='keyword'
>typedef
</SPAN> <SPAN CLASS='omitted'
>[implementation-defined]
</SPAN> category;
167 <A CLASS='documented' HREF='#mapped_file_source_default_ctor'
>mapped_file_source
</A>();
168 <SPAN CLASS='keyword'
>explicit
</SPAN> <A CLASS='documented' HREF='#mapped_file_source_params_ctor'
>mapped_file_source
</A>(
<A CLASS='documented' HREF='#mapped_file_params'
>mapped_file_params
</A> params);
169 <SPAN CLASS='keyword'
>explicit
</SPAN> <A CLASS='documented' HREF='#mapped_file_source_basic_ctor'
>mapped_file_source
</A>(
<SPAN CLASS='keyword'
>const
</SPAN> std::string
& path,
170 size_type length = max_length,
171 boost::intmax_t offset =
<SPAN CLASS='numeric_literal'
>0</SPAN> );
172 void
<A CLASS='documented' HREF='#mapped_file_source_params_open'
>open
</A>(
<A CLASS='documented' HREF='#mapped_file_params'
>mapped_file_params
</A> params);
173 void
<A CLASS='documented' HREF='#mapped_file_source_basic_open'
>open
</A>(
<SPAN CLASS='keyword'
>const
</SPAN> std::string
& path,
174 size_type length = max_length,
175 boost::intmax_t offset =
<SPAN CLASS='numeric_literal'
>0</SPAN> );
176 <SPAN CLASS='keyword'
>bool
</SPAN> <A CLASS='documented' HREF='#mapped_file_source_is_open'
>is_open
</A>()
<SPAN CLASS='keyword'
>const
</SPAN>;
177 <SPAN CLASS='keyword'
>void
</SPAN> <A CLASS='documented' HREF='#mapped_file_source_close'
>close
</A>();
178 size_type
<A CLASS='documented' HREF='#mapped_file_source_size'
>size
</A>()
<SPAN CLASS='keyword'
>const
</SPAN>;
179 <SPAN CLASS='keyword'
>const
</SPAN> <SPAN CLASS='keyword'
>char
</SPAN>*
<A CLASS='documented' HREF='#mapped_file_source_data'
>data
</A>()
<SPAN CLASS='keyword'
>const
</SPAN>;
180 <SPAN CLASS='keyword'
>static
</SPAN> <SPAN CLASS='keyword'
>int
</SPAN> <A CLASS='documented' HREF='#mapped_file_source_alignment'
>alignment
</A>();
183 } } // End namespace boost::io
</PRE>
185 <A NAME=
"mapped_file_source_default_ctor"></A>
186 <H4><CODE>mapped_file_source::mapped_file_source
</CODE></H4>
188 <PRE CLASS=
"broken_ie"> mapped_file_source();
</PRE>
190 <P>Constructs a
<CODE>mapped_file_source
</CODE> which must be opened before it can be used to perform i/o.
</P>
192 <A NAME=
"mapped_file_source_params_ctor"></A>
193 <PRE CLASS=
"broken_ie"> <SPAN CLASS='keyword'
>explicit
</SPAN> mapped_file_source(
<A CLASS='documented' HREF='#mapped_file_params'
>mapped_file_params
</A> params);
</PRE>
195 <P>Constructs a
<CODE>mapped_file_source
</CODE> from the given parameters.
</P>
197 <A NAME=
"mapped_file_source_basic_ctor"></A>
198 <PRE CLASS=
"broken_ie"> <SPAN CLASS='keyword'
>explicit
</SPAN> mapped_file_source(
<SPAN CLASS='keyword'
>const
</SPAN> std::string
& path,
199 size_type length = max_length,
200 boost::intmax_t offset =
<SPAN CLASS='numeric_literal'
>0</SPAN> );
</PRE>
202 <P>Constructs a
<CODE>mapped_file_source
</CODE> to access a specified file. The parameters have the following interpretation:
</P>
204 <TABLE STYLE=
"margin-left:2em" BORDER=
0 CELLPADDING=
2>
207 <TD VALIGN=
"top"><I>path
</I></TD><TD WIDTH=
"2em" VALIGN=
"top">-
</TD>
208 <TD>The pathname of the file to map.
</TD>
211 <TD VALIGN=
"top"><I>length
</I></TD><TD WIDTH=
"2em" VALIGN=
"top">-
</TD>
212 <TD>The number of bytes to map. If this parameter is not specified, the entire file is mapped.
</TD>
215 <TD VALIGN=
"top"><I>offset
</I></TD><TD WIDTH=
"2em" VALIGN=
"top">-
</TD>
216 <TD>The offset where the mapping is to begin. This value must be a multiple of the operating system's virtual memory allocation granularity, which can be obtained using the static member function
<A HREF='#mapped_file_source_alignment'
><CODE>alignment
</CODE></A>.
</TD>
220 <A NAME=
"mapped_file_source_params_open"></A>
221 <H4><CODE>mapped_file_source::open
</CODE></H4>
223 <PRE CLASS=
"broken_ie"> void open(
<A CLASS='documented' HREF='#mapped_file_params'
>mapped_file_params
</A> params);
</PRE>
225 <P>Connects this
<CODE>mapped_file_source
</CODE> to a memory-mapped file obtained as described by the given parameters.
</P>
227 <A NAME=
"mapped_file_source_basic_open"></A>
228 <PRE CLASS=
"broken_ie"> void open(
<SPAN CLASS='keyword'
>const
</SPAN> std::string
& path,
229 size_type length = max_length,
230 boost::intmax_t offset =
<SPAN CLASS='numeric_literal'
>0</SPAN> );
</PRE>
232 <P>Connects this
<CODE>mapped_file_source
</CODE> to a memory-mapped file obtained as described by the given parameters, which have the following interpretation:
</P>
234 <TABLE STYLE=
"margin-left:2em" BORDER=
0 CELLPADDING=
2>
237 <TD VALIGN=
"top"><I>path
</I></TD><TD WIDTH=
"2em" VALIGN=
"top">-
</TD>
238 <TD>The pathname of the file to map.
</TD>
241 <TD VALIGN=
"top"><I>length
</I></TD><TD WIDTH=
"2em" VALIGN=
"top">-
</TD>
242 <TD>The number of bytes to map. If this parameter is not specified, the entire file is mapped.
</TD>
245 <TD VALIGN=
"top"><I>offset
</I></TD><TD WIDTH=
"2em" VALIGN=
"top">-
</TD>
246 <TD>The offset where the mapping is to begin. This value must be a multiple of the operating system's virtual memory allocation granularity, which can be obtained using the static member function
<A HREF='#mapped_file_source_alignment'
><CODE>alignment
</CODE></A>.
</TD>
250 <A NAME=
"mapped_file_source_is_open"></A>
251 <H4><CODE>mapped_file_source::is_open
</CODE></H4>
253 <PRE CLASS=
"broken_ie"> <SPAN CLASS='keyword'
>bool
</SPAN> is_open()
<SPAN CLASS='keyword'
>const
</SPAN>;
</PRE>
255 <P>Returns
<CODE>true
</CODE> if this
<CODE>mapped_file_source
</CODE> has been successfully opened without subsequently having been closed.
</P>
257 <A NAME=
"mapped_file_source_close"></A>
258 <H4><CODE>mapped_file_source::close
</CODE></H4>
260 <PRE CLASS=
"broken_ie"> <SPAN CLASS='keyword'
>void
</SPAN> close();
</PRE>
262 <P>Frees the mapping associated with this
<CODE>mapped_file_source
</CODE>.
</P>
264 <A NAME=
"mapped_file_source_size"></A>
265 <H4><CODE>mapped_file_source::size
</CODE></H4>
267 <PRE CLASS=
"broken_ie"> size_type size()
<SPAN CLASS='keyword'
>const
</SPAN>;
</PRE>
269 <P>Returns the size in bytes of the mapping associated with this
<CODE>mapped_file_source
</CODE>.
</P>
271 <A NAME=
"mapped_file_source_data"></A>
272 <H4><CODE>mapped_file_source::data
</CODE></H4>
274 <PRE CLASS=
"broken_ie"> <SPAN CLASS='keyword'
>const
</SPAN> <SPAN CLASS='keyword'
>char
</SPAN>* data()
<SPAN CLASS='keyword'
>const
</SPAN>;
</PRE>
276 <P>Returns a pointer to the first byte of data in the mapping associated with this
<CODE>mapped_file_source
</CODE>.
</P>
278 <A NAME=
"mapped_file_source_alignment"></A>
279 <H4><CODE>mapped_file_source::alignment
</CODE></H4>
281 <PRE CLASS=
"broken_ie"> <SPAN CLASS='keyword'
>static
</SPAN> <SPAN CLASS='keyword'
>int
</SPAN> alignment();
</PRE>
283 <P>Returns the operating system's virtual memory allocation granularity.
</P>
285 <A NAME=
"mapped_file_sink"></A>
286 <H3>3. Class
<CODE>mapped_file_sink
</CODE></H3>
290 <P>Model of
<A HREF=
"../concepts/sink.html">Sink
</A> providing write-only access to memory-mapped files on Windows and POSIX systems.
</P>
294 <PRE CLASS=
"broken_ie"><SPAN CLASS=
"keyword">namespace
</SPAN> boost {
<SPAN CLASS=
"keyword">namespace
</SPAN> iostreams {
296 <SPAN CLASS=
"keyword">class
</SPAN> <SPAN CLASS=
"defined">mapped_file_sink
</SPAN> {
297 <SPAN CLASS=
"keyword">public
</SPAN>:
298 <SPAN CLASS='keyword'
>typedef
</SPAN> <SPAN CLASS='keyword'
>char
</SPAN> char_type;
299 <SPAN CLASS='keyword'
>typedef
</SPAN> <SPAN CLASS='omitted'
>[implementation-defined]
</SPAN> category;
300 <SPAN CLASS='keyword'
>enum
</SPAN> mapmode { readwrite, priv };
301 <A CLASS='documented' HREF='#mapped_file_sink_default_ctor'
>mapped_file_sink
</A>();
302 <SPAN CLASS='keyword'
>explicit
</SPAN> <A CLASS='documented' HREF='#mapped_file_sink_params_ctor'
>mapped_file_sink
</A>(
<A CLASS='documented' HREF='#mapped_file_params'
>mapped_file_params
</A> params);
303 <SPAN CLASS='keyword'
>explicit
</SPAN> <A CLASS='documented' HREF='#mapped_file_sink_basic_ctor'
>mapped_file_sink
</A>(
<SPAN CLASS='keyword'
>const
</SPAN> std::string
& path,
304 size_type length = max_length,
305 boost::intmax_t offset =
<SPAN CLASS='numeric_literal'
>0</SPAN>,
306 mapmode flags = readwrite );
307 void
<A CLASS='documented' HREF='#mapped_file_sink_params_open'
>open
</A>(
<A CLASS='documented' HREF='#mapped_file_params'
>mapped_file_params
</A> params);
308 void
<A CLASS='documented' HREF='#mapped_file_sink_basic_open'
>open
</A>(
<SPAN CLASS='keyword'
>const
</SPAN> std::string
& path,
309 size_type length = max_length,
310 boost::intmax_t offset =
<SPAN CLASS='numeric_literal'
>0</SPAN>,
311 mapmode flags = readwrite );
312 <SPAN CLASS='keyword'
>bool
</SPAN> <A CLASS='documented' HREF='#mapped_file_sink_is_open'
>is_open
</A>()
<SPAN CLASS='keyword'
>const
</SPAN>;
313 mapmode
<A CLASS='documented' HREF='#mapped_file_sink_flags'
>flags
</A>()
<SPAN CLASS='keyword'
>const
</SPAN>;
314 <SPAN CLASS='keyword'
>void
</SPAN> <A CLASS='documented' HREF='#mapped_file_sink_close'
>close
</A>();
315 size_type
<A CLASS='documented' HREF='#mapped_file_sink_size'
>size
</A>()
<SPAN CLASS='keyword'
>const
</SPAN>;
316 <SPAN CLASS='keyword'
>char
</SPAN>*
<A CLASS='documented' HREF='#mapped_file_sink_data'
>data
</A>()
<SPAN CLASS='keyword'
>const
</SPAN>;
317 <SPAN CLASS='keyword'
>static
</SPAN> <SPAN CLASS='keyword'
>int
</SPAN> <A CLASS='documented' HREF='#mapped_file_sink_alignment'
>alignment
</A>();
320 } } // End namespace boost::io
</PRE>
322 <A NAME=
"mapped_file_sink_default_ctor"></A>
323 <H4><CODE>mapped_file_sink::mapped_file_sink
</CODE></H4>
325 <PRE CLASS=
"broken_ie"> mapped_file_sink();
</PRE>
327 <P>Constructs a
<CODE>mapped_file_sink
</CODE> which must be opened before it can be used to perform i/o.
</P>
329 <A NAME=
"mapped_file_sink_params_ctor"></A>
330 <PRE CLASS=
"broken_ie"> <SPAN CLASS='keyword'
>explicit
</SPAN> mapped_file_sink(
<A CLASS='documented' HREF='#mapped_file_params'
>mapped_file_params
</A> params);
</PRE>
332 <P>Constructs a
<CODE>mapped_file_sink
</CODE> from the given parameters.
</P>
334 <A NAME=
"mapped_file_sink_basic_ctor"></A>
335 <PRE CLASS=
"broken_ie"> <SPAN CLASS='keyword'
>explicit
</SPAN> mapped_file_sink(
<SPAN CLASS='keyword'
>const
</SPAN> std::string
& path,
336 size_type length = max_length,
337 boost::intmax_t offset =
<SPAN CLASS='numeric_literal'
>0</SPAN>,
338 mapmode flags );
</PRE>
340 <P>Constructs a
<CODE>mapped_file_sink
</CODE> to access a specified file. The parameters have the following interpretation:
</P>
342 <TABLE STYLE=
"margin-left:2em" BORDER=
0 CELLPADDING=
2>
345 <TD VALIGN=
"top"><I>path
</I></TD><TD WIDTH=
"2em" VALIGN=
"top">-
</TD>
346 <TD>The pathname of the file to map.
</TD>
349 <TD VALIGN=
"top"><I>length
</I></TD><TD WIDTH=
"2em" VALIGN=
"top">-
</TD>
350 <TD>The number of bytes to map. If this parameter is not specified, the entire file is mapped.
</TD>
353 <TD VALIGN=
"top"><I>offset
</I></TD><TD WIDTH=
"2em" VALIGN=
"top">-
</TD>
354 <TD>The offset where the mapping is to begin. This value must be a multiple of the operating system's virtual memory allocation granularity, which can be obtained using the static member function
<A HREF='#mapped_file_sink_alignment'
><CODE>alignment
</CODE></A>.
</TD>
357 <TD VALIGN=
"top"><I>flags
</I></TD><TD WIDTH=
"2em" VALIGN=
"top">-
</TD>
358 <TD>Indicates whether the
<CODE>mapped_file_sink
</CODE> should be opened for read-write access or private access.
</TD>
362 <A NAME=
"mapped_file_sink_params_open"></A>
363 <H4><CODE>mapped_file_sink::open
</CODE></H4>
365 <PRE CLASS=
"broken_ie"> void open(
<A CLASS='documented' HREF='#mapped_file_params'
>mapped_file_params
</A> params);
</PRE>
367 <P>Connects this
<CODE>mapped_file_sink
</CODE> to a memory-mapped file obtained as described by the given parameters.
</P>
369 <A NAME=
"mapped_file_sink_basic_open"></A>
370 <PRE CLASS=
"broken_ie"> void open(
<SPAN CLASS='keyword'
>const
</SPAN> std::string
& path,
371 size_type length = max_length,
372 boost::intmax_t offset =
<SPAN CLASS='numeric_literal'
>0</SPAN>
373 mapmode flags );
</PRE>
375 <P>Connects this
<CODE>mapped_file_sink
</CODE> to a memory-mapped file obtained as described by the given parameters, which have the following interpretation:
</P>
377 <TABLE STYLE=
"margin-left:2em" BORDER=
0 CELLPADDING=
2>
380 <TD VALIGN=
"top"><I>path
</I></TD><TD WIDTH=
"2em" VALIGN=
"top">-
</TD>
381 <TD>The pathname of the file to map.
</TD>
384 <TD VALIGN=
"top"><I>length
</I></TD><TD WIDTH=
"2em" VALIGN=
"top">-
</TD>
385 <TD>The number of bytes to map. If this parameter is not specified, the entire file is mapped.
</TD>
388 <TD VALIGN=
"top"><I>offset
</I></TD><TD WIDTH=
"2em" VALIGN=
"top">-
</TD>
389 <TD>The offset where the mapping is to begin. This value must be a multiple of the operating system's virtual memory allocation granularity, which can be obtained using the static member function
<A HREF='#mapped_file_sink_alignment'
><CODE>alignment
</CODE></A>.
</TD>
392 <TD VALIGN=
"top"><I>flags
</I></TD><TD WIDTH=
"2em" VALIGN=
"top">-
</TD>
393 <TD>Indicates whether the
<CODE>mapped_file_sink
</CODE> should be opened for read-write access or private access.
</TD>
397 <A NAME=
"mapped_file_sink_is_open"></A>
398 <H4><CODE>mapped_file_sink::is_open
</CODE></H4>
400 <PRE CLASS=
"broken_ie"> <SPAN CLASS='keyword'
>bool
</SPAN> is_open()
<SPAN CLASS='keyword'
>const
</SPAN>;
</PRE>
402 <P>Returns
<CODE>true
</CODE> if this
<CODE>mapped_file_sink
</CODE> has been successfully opened without subsequently having been closed.
</P>
404 <A NAME=
"mapped_file_sink_flags"></A>
405 <H4><CODE>mapped_file_sink::flags
</CODE></H4>
407 <PRE CLASS=
"broken_ie"> mapmode flags()
<SPAN CLASS='keyword'
>const
</SPAN>;
</PRE>
409 <P>Indicates whether the
<CODE>mapped_file_sink
</CODE> was opened for read/write-access or private-access.
</P>
411 <A NAME=
"mapped_file_sink_close"></A>
412 <H4><CODE>mapped_file_sink::close
</CODE></H4>
414 <PRE CLASS=
"broken_ie"> <SPAN CLASS='keyword'
>void
</SPAN> close();
</PRE>
416 <P>Frees the mapping associated with this
<CODE>mapped_file_sink
</CODE>.
</P>
418 <A NAME=
"mapped_file_sink_size"></A>
419 <H4><CODE>mapped_file_sink::size
</CODE></H4>
421 <PRE CLASS=
"broken_ie"> size_type size()
<SPAN CLASS='keyword'
>const
</SPAN>;
</PRE>
423 <P>Returns the size in bytes of the mapping associated with this
<CODE>mapped_file_sink
</CODE>.
</P>
425 <A NAME=
"mapped_file_sink_data"></A>
426 <H4><CODE>mapped_file_sink::data
</CODE></H4>
428 <PRE CLASS=
"broken_ie"> <SPAN CLASS='keyword'
>char
</SPAN>* data()
<SPAN CLASS='keyword'
>const
</SPAN>;
</PRE>
430 <P>Returns a pointer to the first byte of data in the mapping associated with this
<CODE>mapped_file_sink
</CODE>.
</P>
432 <A NAME=
"mapped_file_sink_alignment"></A>
433 <H4><CODE>mapped_file_sink::alignment
</CODE></H4>
435 <PRE CLASS=
"broken_ie"> <SPAN CLASS='keyword'
>static
</SPAN> <SPAN CLASS='keyword'
>int
</SPAN> alignment();
</PRE>
437 <P>Returns the operating system's virtual memory allocation granularity.
</P>
439 <A NAME=
"mapped_file"></A>
440 <H3>4. Class
<CODE>mapped_file
</CODE></H3>
444 <P>Model of
<A HREF=
"../concepts/seekable_device.html">SeekableDevice
</A> providing read-write access to memory-mapped files on Windows and POSIX systems.
</P>
448 <PRE CLASS=
"broken_ie"><SPAN CLASS=
"keyword">namespace
</SPAN> boost {
<SPAN CLASS=
"keyword">namespace
</SPAN> iostreams {
450 <SPAN CLASS=
"keyword">class
</SPAN> <SPAN CLASS=
"defined">mapped_file
</SPAN> {
451 <SPAN CLASS=
"keyword">public
</SPAN>:
452 <SPAN CLASS='keyword'
>typedef
</SPAN> <SPAN CLASS='keyword'
>char
</SPAN> char_type;
453 <SPAN CLASS='keyword'
>typedef
</SPAN> <SPAN CLASS='omitted'
>[implementation-defined]
</SPAN> category;
454 <SPAN CLASS='keyword'
>enum
</SPAN> mapmode { readonly, readwrite, priv };
455 <A CLASS='documented' HREF='#mapped_file_default_ctor'
>mapped_file
</A>();
456 <SPAN CLASS='keyword'
>explicit
</SPAN> <A CLASS='documented' HREF='#mapped_file_params_ctor'
>mapped_file
</A>(
<A CLASS='documented' HREF='#mapped_file_params'
>mapped_file_params
</A> params);
457 <SPAN CLASS='keyword'
>explicit
</SPAN> <A CLASS='documented' HREF='#mapped_file_basic_ctor'
>mapped_file
</A>(
<SPAN CLASS='keyword'
>const
</SPAN> std::string
& path,
458 std::ios_base::openmode mode =
459 std::ios_base::in | std::ios_base::out,
460 size_type length = max_length,
461 boost::intmax_t offset =
<SPAN CLASS='numeric_literal'
>0</SPAN> );
462 <SPAN CLASS='keyword'
>explicit
</SPAN> <A CLASS='documented' HREF='#mapped_file_mapmode_ctor'
>mapped_file
</A>(
<SPAN CLASS='keyword'
>const
</SPAN> std::string
& path,
464 size_type length = max_length,
465 boost::intmax_t offset =
<SPAN CLASS='numeric_literal'
>0</SPAN> );
466 <SPAN CLASS='keyword'
>void
</SPAN> <A CLASS='documented' HREF='#mapped_file_params_open'
>open
</A>(
<A CLASS='documented' HREF='#mapped_file_params'
>mapped_file_params
</A> params);
467 <SPAN CLASS='keyword'
>void
</SPAN> <A CLASS='documented' HREF='#mapped_file_basic_open'
>open
</A>(
<SPAN CLASS='keyword'
>const
</SPAN> std::string
& path,
468 std::ios_base::openmode mode =
469 std::ios_base | std::ios_base,
470 size_type length = max_length,
471 boost::intmax_t offset =
<SPAN CLASS='numeric_literal'
>0</SPAN> );
472 <SPAN CLASS='keyword'
>void
</SPAN> <A CLASS='documented' HREF='#mapped_file_mapmode_open'
>open
</A>(
<SPAN CLASS='keyword'
>const
</SPAN> std::string
& path,
474 size_type length = max_length,
475 boost::intmax_t offset =
<SPAN CLASS='numeric_literal'
>0</SPAN> );
476 <SPAN CLASS='keyword'
>bool
</SPAN> <A CLASS='documented' HREF='#mapped_file_is_open'
>is_open
</A>()
<SPAN CLASS='keyword'
>const
</SPAN>;
477 mapmode
<A CLASS='documented' HREF='#mapped_file_flags'
>flags
</A>()
<SPAN CLASS='keyword'
>const
</SPAN>;
478 <SPAN CLASS='keyword'
>void
</SPAN> <A CLASS='documented' HREF='#mapped_file_close'
>close
</A>();
479 size_type
<A CLASS='documented' HREF='#mapped_file_size'
>size
</A>()
<SPAN CLASS='keyword'
>const
</SPAN>;
480 <SPAN CLASS='keyword'
>char
</SPAN>*
<A CLASS='documented' HREF='#mapped_file_data'
>data
</A>()
<SPAN CLASS='keyword'
>const
</SPAN>;
481 <SPAN CLASS='keyword'
>const
</SPAN> <SPAN CLASS='keyword'
>char
</SPAN>*
<A CLASS='documented' HREF='#mapped_file_const_data'
>const_data
</A>()
<SPAN CLASS='keyword'
>const
</SPAN>;
482 <SPAN CLASS='keyword'
>static
</SPAN> <SPAN CLASS='keyword'
>int
</SPAN> <A CLASS='documented' HREF='#mapped_file_alignment'
>alignment
</A>();
485 } } // End namespace boost::iostreams
</PRE>
487 <A NAME=
"mapped_file_default_ctor"></A>
488 <H4><CODE>mapped_file::mapped_file
</CODE></H4>
490 <PRE CLASS=
"broken_ie"> mapped_file();
</PRE>
492 <P>Constructs a
<CODE>mapped_file
</CODE> which must be opened before it can be used to perform i/o.
</P>
494 <A NAME=
"mapped_file_params_ctor"></A>
495 <PRE CLASS=
"broken_ie"> <SPAN CLASS='keyword'
>explicit
</SPAN> mapped_file(
<A CLASS='documented' HREF='#mapped_file_params'
>mapped_file_params
</A> params);
</PRE>
497 <P>Constructs a
<CODE>mapped_file
</CODE> from the given parameters.
</P>
499 <A NAME=
"mapped_file_basic_ctor"></A>
500 <PRE CLASS=
"broken_ie"> <SPAN CLASS='keyword'
>explicit
</SPAN> mapped_file(
<SPAN CLASS='keyword'
>const
</SPAN> std::string
& path,
501 std::ios_base::openmode mode =
502 std::ios_base | std::ios_base,
503 size_type length = max_length,
504 boost::intmax_t offset =
<SPAN CLASS='numeric_literal'
>0</SPAN> );
</PRE>
506 <P>Constructs a
<CODE>mapped_file
</CODE> to access a specified file. The parameters have the following interpretation:
</P>
508 <TABLE STYLE=
"margin-left:2em" BORDER=
0 CELLPADDING=
2>
511 <TD VALIGN=
"top"><I>path
</I></TD><TD WIDTH=
"2em" VALIGN=
"top">-
</TD>
512 <TD>The pathname of the file to map.
</TD>
515 <TD VALIGN=
"top"><I>mode
</I></TD><TD WIDTH=
"2em" VALIGN=
"top">-
</TD>
516 <TD>Indicates whether the file should be opened with read-access, write-access or both. Use of
<CODE>std::ios_base::openmode
</CODE> with
<CODE>mapped_file
</CODE> is deprecated. Please use
<CODE>mapmode
</CODE> instead in new code.
</TD>
519 <TD VALIGN=
"top"><I>length
</I></TD><TD WIDTH=
"2em" VALIGN=
"top">-
</TD>
520 <TD>The number of bytes to map. If this parameter is not specified, the entire file is mapped.
</TD>
523 <TD VALIGN=
"top"><I>offset
</I></TD><TD WIDTH=
"2em" VALIGN=
"top">-
</TD>
524 <TD>The offset where the mapping is to begin. This value must be a multiple of the operating system's virtual memory allocation granularity, which can be obtained using the static member function
<A HREF='#mapped_file_alignment'
><CODE>alignment
</CODE></A>.
</TD>
528 <A NAME=
"mapped_file_mapmode_ctor"></A>
529 <PRE CLASS=
"broken_ie"> <SPAN CLASS='keyword'
>explicit
</SPAN> mapped_file(
<SPAN CLASS='keyword'
>const
</SPAN> std::string
& path,
531 size_type length = max_length,
532 boost::intmax_t offset =
<SPAN CLASS='numeric_literal'
>0</SPAN> );
</PRE>
534 <P>Constructs a
<CODE>mapped_file
</CODE> to access a specified file. The parameters have the following interpretation:
</P>
536 <TABLE STYLE=
"margin-left:2em" BORDER=
0 CELLPADDING=
2>
539 <TD VALIGN=
"top"><I>path
</I></TD><TD WIDTH=
"2em" VALIGN=
"top">-
</TD>
540 <TD>The pathname of the file to map.
</TD>
543 <TD VALIGN=
"top"><I>mode
</I></TD><TD WIDTH=
"2em" VALIGN=
"top">-
</TD>
544 <TD>Indicates whether the file should be opened with read-access, read/write-access or private-access.
</TD>
547 <TD VALIGN=
"top"><I>length
</I></TD><TD WIDTH=
"2em" VALIGN=
"top">-
</TD>
548 <TD>The number of bytes to map. If this parameter is not specified, the entire file is mapped.
</TD>
551 <TD VALIGN=
"top"><I>offset
</I></TD><TD WIDTH=
"2em" VALIGN=
"top">-
</TD>
552 <TD>The offset where the mapping is to begin. This value must be a multiple of the operating system's virtual memory allocation granularity, which can be obtained using the static member function
<A HREF='#mapped_file_alignment'
><CODE>alignment
</CODE></A>.
</TD>
556 <A NAME=
"mapped_file_params_open"></A>
557 <H4><CODE>mapped_file::open
</CODE></H4>
559 <PRE CLASS=
"broken_ie"> void open(
<A CLASS='documented' HREF='#mapped_file_params'
>mapped_file_params
</A> params);
</PRE>
561 <P>Connects this
<CODE>mapped_file
</CODE> to a memory-mapped file obtained as described by the given parameters.
</P>
563 <A NAME=
"mapped_file_basic_open"></A>
564 <PRE CLASS=
"broken_ie"> void open(
<SPAN CLASS='keyword'
>const
</SPAN> std::string
& path,
565 std::ios_base::openmode mode =
566 std::ios_base | std::ios_base,
567 size_type length = max_length,
568 boost::intmax_t offset =
<SPAN CLASS='numeric_literal'
>0</SPAN> );
</PRE>
570 <P>Connects this
<CODE>mapped_file
</CODE> to a memory-mapped file obtained as described by the given parameters, which have the following interpretation:
</P>
572 <TABLE STYLE=
"margin-left:2em" BORDER=
0 CELLPADDING=
2>
575 <TD VALIGN=
"top"><I>path
</I></TD><TD WIDTH=
"2em" VALIGN=
"top">-
</TD>
576 <TD>The pathname of the file to map.
</TD>
579 <TD VALIGN=
"top"><I>mode
</I></TD><TD WIDTH=
"2em" VALIGN=
"top">-
</TD>
580 <TD>Indicates whether the file should be opened with read-access, write-access or both. Use of
<CODE>std::ios_base::openmode
</CODE> with
<CODE>mapped_file
</CODE> is deprecated. Please use
<CODE>mapmode
</CODE> in new code.
</TD>
583 <TD VALIGN=
"top"><I>length
</I></TD><TD WIDTH=
"2em" VALIGN=
"top">-
</TD>
584 <TD>The number of bytes to map. If this parameter is not specified, the entire file is mapped.
</TD>
587 <TD VALIGN=
"top"><I>offset
</I></TD><TD WIDTH=
"2em" VALIGN=
"top">-
</TD>
588 <TD>The offset where the mapping is to begin. This value must be a multiple of the operating system's virtual memory allocation granularity, which can be obtained using the static member function
<A HREF='#mapped_file_alignment'
><CODE>alignment
</CODE></A>.
</TD>
592 <A NAME=
"mapped_file_mapmode_open"></A>
593 <PRE CLASS=
"broken_ie"> void open(
<SPAN CLASS='keyword'
>const
</SPAN> std::string
& path,
595 size_type length = max_length,
596 boost::intmax_t offset =
<SPAN CLASS='numeric_literal'
>0</SPAN> );
</PRE>
598 <P>Connects this
<CODE>mapped_file
</CODE> to a memory-mapped file obtained as described by the given parameters, which have the following interpretation:
</P>
600 <TABLE STYLE=
"margin-left:2em" BORDER=
0 CELLPADDING=
2>
603 <TD VALIGN=
"top"><I>path
</I></TD><TD WIDTH=
"2em" VALIGN=
"top">-
</TD>
604 <TD>The pathname of the file to map.
</TD>
607 <TD VALIGN=
"top"><I>mode
</I></TD><TD WIDTH=
"2em" VALIGN=
"top">-
</TD>
608 <TD>Indicates whether the file should be opened with read-access, read/write-access or private access.
</TD>
611 <TD VALIGN=
"top"><I>length
</I></TD><TD WIDTH=
"2em" VALIGN=
"top">-
</TD>
612 <TD>The number of bytes to map. If this parameter is not specified, the entire file is mapped.
</TD>
615 <TD VALIGN=
"top"><I>offset
</I></TD><TD WIDTH=
"2em" VALIGN=
"top">-
</TD>
616 <TD>The offset where the mapping is to begin. This value must be a multiple of the operating system's virtual memory allocation granularity, which can be obtained using the static member function
<A HREF='#mapped_file_alignment'
><CODE>alignment
</CODE></A>.
</TD>
620 <A NAME=
"mapped_file_is_open"></A>
621 <H4><CODE>mapped_file::is_open
</CODE></H4>
623 <PRE CLASS=
"broken_ie"> <SPAN CLASS='keyword'
>bool
</SPAN> is_open()
<SPAN CLASS='keyword'
>const
</SPAN>;
</PRE>
625 <P>Returns
<CODE>true
</CODE> if this
<CODE>mapped_file
</CODE> has been successfully opened without subsequently having been closed.
</P>
627 <A NAME=
"mapped_file_flags"></A>
628 <H4><CODE>mapped_file::flags
</CODE></H4>
630 <PRE CLASS=
"broken_ie"> mapmode flags()
<SPAN CLASS='keyword'
>const
</SPAN>;
</PRE>
632 <P>Indicates whether the
<CODE>mapped_file
</CODE> was opened for read-access, read/write-access or private-access.
</P>
634 <A NAME=
"mapped_file_close"></A>
635 <H4><CODE>mapped_file::close
</CODE></H4>
637 <PRE CLASS=
"broken_ie"> <SPAN CLASS='keyword'
>void
</SPAN> close();
</PRE>
639 <P>Frees the mapping associated with this
<CODE>mapped_file
</CODE>.
</P>
641 <A NAME=
"mapped_file_size"></A>
642 <H4><CODE>mapped_file::size
</CODE></H4>
644 <PRE CLASS=
"broken_ie"> size_type size()
<SPAN CLASS='keyword'
>const
</SPAN>;
</PRE>
646 <P>Returns the size in bytes of the mapping associated with this
<CODE>mapped_file
</CODE>.
</P>
648 <A NAME=
"mapped_file_data"></A>
649 <H4><CODE>mapped_file::data
</CODE></H4>
651 <PRE CLASS=
"broken_ie"> <SPAN CLASS='keyword'
>char
</SPAN>* data()
<SPAN CLASS='keyword'
>const
</SPAN>;
</PRE>
653 <P>Returns a pointer to the first byte of data in the mapping associated with this
<CODE>mapped_file
</CODE>, if it was opened with write-access, and a null pointer otherwise.
</P>
655 <A NAME=
"mapped_file_const_data"></A>
656 <H4><CODE>mapped_file::const_data
</CODE></H4>
658 <PRE CLASS=
"broken_ie"> <SPAN CLASS='keyword'
>const
</SPAN> <SPAN CLASS='keyword'
>char
</SPAN>* const_data()
<SPAN CLASS='keyword'
>const
</SPAN>;
</PRE>
660 <P>Returns a pointer to the first byte of data in the mapping associated with this
<CODE>mapped_file
</CODE>.
</P>
662 <A NAME=
"mapped_file_alignment"></A>
663 <H4><CODE>mapped_file::alignment
</CODE></H4>
665 <PRE CLASS=
"broken_ie"> <SPAN CLASS='keyword'
>static
</SPAN> <SPAN CLASS='keyword'
>int
</SPAN> alignment();
</PRE>
667 <P>Returns the operating system's virtual memory allocation granularity.
</P>
669 <!-- Begin Footer -->
673 <P CLASS=
"copyright">© Copyright
2008 <a href=
"http://www.coderage.com/" target=
"_top">CodeRage, LLC
</a><br/>© Copyright
2004-
2007 <a href=
"http://www.coderage.com/turkanis/" target=
"_top">Jonathan Turkanis
</a></P>
674 <P CLASS=
"copyright">
675 Distributed under the Boost Software License, Version
1.0. (See accompanying file LICENSE_1_0.txt or copy at
<A HREF=
"http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt
</A>)