mio 1.1.0
Loading...
Searching...
No Matches
mio::basic_shared_mmap< AccessMode, ByteT > Class Template Reference

#include <shared_mmap.hpp>

Public Types

using value_type = typename impl_type::value_type
 
using size_type = typename impl_type::size_type
 
using reference = typename impl_type::reference
 
using const_reference = typename impl_type::const_reference
 
using pointer = typename impl_type::pointer
 
using const_pointer = typename impl_type::const_pointer
 
using difference_type = typename impl_type::difference_type
 
using iterator = typename impl_type::iterator
 
using const_iterator = typename impl_type::const_iterator
 
using reverse_iterator = typename impl_type::reverse_iterator
 
using const_reverse_iterator = typename impl_type::const_reverse_iterator
 
using iterator_category = typename impl_type::iterator_category
 
using handle_type = typename impl_type::handle_type
 
using mmap_type = impl_type
 

Public Member Functions

 basic_shared_mmap ()=default
 
 basic_shared_mmap (const basic_shared_mmap &)=default
 
basic_shared_mmapoperator= (const basic_shared_mmap &)=default
 
 basic_shared_mmap (basic_shared_mmap &&)=default
 
basic_shared_mmapoperator= (basic_shared_mmap &&)=default
 
 basic_shared_mmap (mmap_type &&mmap)
 
basic_shared_mmapoperator= (mmap_type &&mmap)
 
 basic_shared_mmap (std::shared_ptr< mmap_type > mmap)
 
basic_shared_mmapoperator= (std::shared_ptr< mmap_type > mmap)
 
 ~basic_shared_mmap ()=default
 
std::shared_ptr< mmap_typeget_shared_ptr ()
 
handle_type file_handle () const noexcept
 
handle_type mapping_handle () const noexcept
 
bool is_open () const noexcept
 
bool empty () const noexcept
 
size_type size () const noexcept
 
size_type length () const noexcept
 
size_type mapped_length () const noexcept
 
template<access_mode A = AccessMode, typename = typename std::enable_if<A == access_mode::write>::type>
pointer data () noexcept
 
const_pointer data () const noexcept
 
iterator begin () noexcept
 
const_iterator begin () const noexcept
 
const_iterator cbegin () const noexcept
 
template<access_mode A = AccessMode, typename = typename std::enable_if<A == access_mode::write>::type>
iterator end () noexcept
 
const_iterator end () const noexcept
 
const_iterator cend () const noexcept
 
template<access_mode A = AccessMode, typename = typename std::enable_if<A == access_mode::write>::type>
reverse_iterator rbegin () noexcept
 
const_reverse_iterator rbegin () const noexcept
 
const_reverse_iterator crbegin () const noexcept
 
template<access_mode A = AccessMode, typename = typename std::enable_if<A == access_mode::write>::type>
reverse_iterator rend () noexcept
 
const_reverse_iterator rend () const noexcept
 
const_reverse_iterator crend () const noexcept
 
reference operator[] (const size_type &i) noexcept
 
const_reference operator[] (const size_type &i) const noexcept
 
template<typename String >
void map (const String &path, const size_type &offset, const size_type &length, std::error_code &error)
 
template<typename String >
void map (const String &path, std::error_code &error)
 
void map (const handle_type &handle, const size_type &offset, const size_type &length, std::error_code &error)
 
void map (const handle_type &handle, std::error_code &error)
 
void unmap ()
 
void swap (basic_shared_mmap &other)
 
template<access_mode A = AccessMode, typename = typename std::enable_if<A == access_mode::write>::type>
void sync (std::error_code &error)
 

Friends

bool operator== (const basic_shared_mmap &a, const basic_shared_mmap &b)
 
bool operator!= (const basic_shared_mmap &a, const basic_shared_mmap &b)
 
bool operator< (const basic_shared_mmap &a, const basic_shared_mmap &b)
 
bool operator<= (const basic_shared_mmap &a, const basic_shared_mmap &b)
 
bool operator> (const basic_shared_mmap &a, const basic_shared_mmap &b)
 
bool operator>= (const basic_shared_mmap &a, const basic_shared_mmap &b)
 

Detailed Description

template<access_mode AccessMode, typename ByteT>
class mio::basic_shared_mmap< AccessMode, ByteT >

Exposes (nearly) the same interface as basic_mmap, but endowes it with std::shared_ptr semantics.

This is not the default behaviour of basic_mmap to avoid allocating on the heap if shared semantics are not required.

Member Typedef Documentation

◆ const_iterator

◆ const_pointer

◆ const_reference

◆ const_reverse_iterator

◆ difference_type

◆ handle_type

◆ iterator

◆ iterator_category

◆ mmap_type

template<access_mode AccessMode, typename ByteT >
using mio::basic_shared_mmap< AccessMode, ByteT >::mmap_type = impl_type

◆ pointer

◆ reference

◆ reverse_iterator

◆ size_type

◆ value_type

Constructor & Destructor Documentation

◆ basic_shared_mmap() [1/5]

template<access_mode AccessMode, typename ByteT >
mio::basic_shared_mmap< AccessMode, ByteT >::basic_shared_mmap ( )
default

◆ basic_shared_mmap() [2/5]

template<access_mode AccessMode, typename ByteT >
mio::basic_shared_mmap< AccessMode, ByteT >::basic_shared_mmap ( const basic_shared_mmap< AccessMode, ByteT > &  )
default

◆ basic_shared_mmap() [3/5]

template<access_mode AccessMode, typename ByteT >
mio::basic_shared_mmap< AccessMode, ByteT >::basic_shared_mmap ( basic_shared_mmap< AccessMode, ByteT > &&  )
default

◆ basic_shared_mmap() [4/5]

template<access_mode AccessMode, typename ByteT >
mio::basic_shared_mmap< AccessMode, ByteT >::basic_shared_mmap ( mmap_type &&  mmap)
inlineexplicit

Takes ownership of an existing mmap object.

◆ basic_shared_mmap() [5/5]

template<access_mode AccessMode, typename ByteT >
mio::basic_shared_mmap< AccessMode, ByteT >::basic_shared_mmap ( std::shared_ptr< mmap_type mmap)
inlineexplicit

Initializes this object with an already established shared mmap.

◆ ~basic_shared_mmap()

If this is a read-write mapping and the last reference to the mapping, the destructor invokes sync. Regardless of the access mode, unmap is invoked as a final step.

Member Function Documentation

◆ begin() [1/2]

template<access_mode AccessMode, typename ByteT >
const_iterator mio::basic_shared_mmap< AccessMode, ByteT >::begin ( ) const
inlinenoexcept

◆ begin() [2/2]

template<access_mode AccessMode, typename ByteT >
iterator mio::basic_shared_mmap< AccessMode, ByteT >::begin ( )
inlinenoexcept

Returns an iterator to the first requested byte, if a valid memory mapping exists, otherwise this function call is undefined behaviour.

◆ cbegin()

template<access_mode AccessMode, typename ByteT >
const_iterator mio::basic_shared_mmap< AccessMode, ByteT >::cbegin ( ) const
inlinenoexcept

◆ cend()

template<access_mode AccessMode, typename ByteT >
const_iterator mio::basic_shared_mmap< AccessMode, ByteT >::cend ( ) const
inlinenoexcept

◆ crbegin()

template<access_mode AccessMode, typename ByteT >
const_reverse_iterator mio::basic_shared_mmap< AccessMode, ByteT >::crbegin ( ) const
inlinenoexcept

◆ crend()

template<access_mode AccessMode, typename ByteT >
const_reverse_iterator mio::basic_shared_mmap< AccessMode, ByteT >::crend ( ) const
inlinenoexcept

◆ data() [1/2]

template<access_mode AccessMode, typename ByteT >
const_pointer mio::basic_shared_mmap< AccessMode, ByteT >::data ( ) const
inlinenoexcept

◆ data() [2/2]

template<access_mode AccessMode, typename ByteT >
template<access_mode A = AccessMode, typename = typename std::enable_if<A == access_mode::write>::type>
pointer mio::basic_shared_mmap< AccessMode, ByteT >::data ( )
inlinenoexcept

Returns a pointer to the first requested byte, or nullptr if no memory mapping exists.

◆ empty()

template<access_mode AccessMode, typename ByteT >
bool mio::basic_shared_mmap< AccessMode, ByteT >::empty ( ) const
inlinenoexcept

Returns true if no mapping was established, that is, conceptually the same as though the length that was mapped was 0. This function is provided so that this class has Container semantics.

◆ end() [1/2]

template<access_mode AccessMode, typename ByteT >
const_iterator mio::basic_shared_mmap< AccessMode, ByteT >::end ( ) const
inlinenoexcept

◆ end() [2/2]

template<access_mode AccessMode, typename ByteT >
template<access_mode A = AccessMode, typename = typename std::enable_if<A == access_mode::write>::type>
iterator mio::basic_shared_mmap< AccessMode, ByteT >::end ( )
inlinenoexcept

Returns an iterator one past the last requested byte, if a valid memory mapping exists, otherwise this function call is undefined behaviour.

◆ file_handle()

template<access_mode AccessMode, typename ByteT >
handle_type mio::basic_shared_mmap< AccessMode, ByteT >::file_handle ( ) const
inlinenoexcept

On UNIX systems 'file_handle' and 'mapping_handle' are the same. On Windows, however, a mapped region of a file gets its own handle, which is returned by 'mapping_handle'.

◆ get_shared_ptr()

template<access_mode AccessMode, typename ByteT >
std::shared_ptr< mmap_type > mio::basic_shared_mmap< AccessMode, ByteT >::get_shared_ptr ( )
inline

Returns the underlying std::shared_ptr instance that holds the mmap.

◆ is_open()

template<access_mode AccessMode, typename ByteT >
bool mio::basic_shared_mmap< AccessMode, ByteT >::is_open ( ) const
inlinenoexcept

Returns whether a valid memory mapping has been created.

◆ length()

template<access_mode AccessMode, typename ByteT >
size_type mio::basic_shared_mmap< AccessMode, ByteT >::length ( ) const
inlinenoexcept

◆ map() [1/4]

template<access_mode AccessMode, typename ByteT >
void mio::basic_shared_mmap< AccessMode, ByteT >::map ( const handle_type handle,
const size_type offset,
const size_type length,
std::error_code &  error 
)
inline

Establishes a memory mapping with AccessMode. If the mapping is unsuccesful, the reason is reported via error and the object remains in a state as if this function hadn't been called.

handle, which must be a valid file handle, which is used to memory map the requested region. Upon failure, error is set to indicate the reason and the object remains in an unmapped state.

offset is the number of bytes, relative to the start of the file, where the mapping should begin. When specifying it, there is no need to worry about providing a value that is aligned with the operating system's page allocation granularity. This is adjusted by the implementation such that the first requested byte (as returned by data or begin), so long as offset is valid, will be at offset from the start of the file.

length is the number of bytes to map. It may be map_entire_file, in which case a mapping of the entire file is created.

◆ map() [2/4]

template<access_mode AccessMode, typename ByteT >
void mio::basic_shared_mmap< AccessMode, ByteT >::map ( const handle_type handle,
std::error_code &  error 
)
inline

Establishes a memory mapping with AccessMode. If the mapping is unsuccesful, the reason is reported via error and the object remains in a state as if this function hadn't been called.

handle, which must be a valid file handle, which is used to memory map the requested region. Upon failure, error is set to indicate the reason and the object remains in an unmapped state.

The entire file is mapped.

◆ map() [3/4]

template<access_mode AccessMode, typename ByteT >
template<typename String >
void mio::basic_shared_mmap< AccessMode, ByteT >::map ( const String path,
const size_type offset,
const size_type length,
std::error_code &  error 
)
inline

Establishes a memory mapping with AccessMode. If the mapping is unsuccesful, the reason is reported via error and the object remains in a state as if this function hadn't been called.

path, which must be a path to an existing file, is used to retrieve a file handle (which is closed when the object destructs or unmap is called), which is then used to memory map the requested region. Upon failure, error is set to indicate the reason and the object remains in an unmapped state.

offset is the number of bytes, relative to the start of the file, where the mapping should begin. When specifying it, there is no need to worry about providing a value that is aligned with the operating system's page allocation granularity. This is adjusted by the implementation such that the first requested byte (as returned by data or begin), so long as offset is valid, will be at offset from the start of the file.

length is the number of bytes to map. It may be map_entire_file, in which case a mapping of the entire file is created.

◆ map() [4/4]

template<access_mode AccessMode, typename ByteT >
template<typename String >
void mio::basic_shared_mmap< AccessMode, ByteT >::map ( const String path,
std::error_code &  error 
)
inline

Establishes a memory mapping with AccessMode. If the mapping is unsuccesful, the reason is reported via error and the object remains in a state as if this function hadn't been called.

path, which must be a path to an existing file, is used to retrieve a file handle (which is closed when the object destructs or unmap is called), which is then used to memory map the requested region. Upon failure, error is set to indicate the reason and the object remains in an unmapped state.

The entire file is mapped.

◆ mapped_length()

template<access_mode AccessMode, typename ByteT >
size_type mio::basic_shared_mmap< AccessMode, ByteT >::mapped_length ( ) const
inlinenoexcept

◆ mapping_handle()

template<access_mode AccessMode, typename ByteT >
handle_type mio::basic_shared_mmap< AccessMode, ByteT >::mapping_handle ( ) const
inlinenoexcept

◆ operator=() [1/4]

◆ operator=() [2/4]

◆ operator=() [3/4]

Takes ownership of an existing mmap object.

◆ operator=() [4/4]

template<access_mode AccessMode, typename ByteT >
basic_shared_mmap & mio::basic_shared_mmap< AccessMode, ByteT >::operator= ( std::shared_ptr< mmap_type mmap)
inline

Initializes this object with an already established shared mmap.

◆ operator[]() [1/2]

template<access_mode AccessMode, typename ByteT >
const_reference mio::basic_shared_mmap< AccessMode, ByteT >::operator[] ( const size_type i) const
inlinenoexcept

◆ operator[]() [2/2]

template<access_mode AccessMode, typename ByteT >
reference mio::basic_shared_mmap< AccessMode, ByteT >::operator[] ( const size_type i)
inlinenoexcept

Returns a reference to the ith byte from the first requested byte (as returned by data). If this is invoked when no valid memory mapping has been created prior to this call, undefined behaviour ensues.

◆ rbegin() [1/2]

template<access_mode AccessMode, typename ByteT >
const_reverse_iterator mio::basic_shared_mmap< AccessMode, ByteT >::rbegin ( ) const
inlinenoexcept

◆ rbegin() [2/2]

template<access_mode AccessMode, typename ByteT >
template<access_mode A = AccessMode, typename = typename std::enable_if<A == access_mode::write>::type>
reverse_iterator mio::basic_shared_mmap< AccessMode, ByteT >::rbegin ( )
inlinenoexcept

Returns a reverse iterator to the last memory mapped byte, if a valid memory mapping exists, otherwise this function call is undefined behaviour.

◆ rend() [1/2]

template<access_mode AccessMode, typename ByteT >
const_reverse_iterator mio::basic_shared_mmap< AccessMode, ByteT >::rend ( ) const
inlinenoexcept

◆ rend() [2/2]

template<access_mode AccessMode, typename ByteT >
template<access_mode A = AccessMode, typename = typename std::enable_if<A == access_mode::write>::type>
reverse_iterator mio::basic_shared_mmap< AccessMode, ByteT >::rend ( )
inlinenoexcept

Returns a reverse iterator past the first mapped byte, if a valid memory mapping exists, otherwise this function call is undefined behaviour.

◆ size()

template<access_mode AccessMode, typename ByteT >
size_type mio::basic_shared_mmap< AccessMode, ByteT >::size ( ) const
inlinenoexcept

size and length both return the logical length, i.e. the number of bytes user requested to be mapped, while mapped_length returns the actual number of bytes that were mapped which is a multiple of the underlying operating system's page allocation granularity.

◆ swap()

template<access_mode AccessMode, typename ByteT >
void mio::basic_shared_mmap< AccessMode, ByteT >::swap ( basic_shared_mmap< AccessMode, ByteT > &  other)
inline

◆ sync()

template<access_mode AccessMode, typename ByteT >
template<access_mode A = AccessMode, typename = typename std::enable_if<A == access_mode::write>::type>
void mio::basic_shared_mmap< AccessMode, ByteT >::sync ( std::error_code &  error)
inline

Flushes the memory mapped page to disk. Errors are reported via error.

◆ unmap()

template<access_mode AccessMode, typename ByteT >
void mio::basic_shared_mmap< AccessMode, ByteT >::unmap ( )
inline

If a valid memory mapping has been created prior to this call, this call instructs the kernel to unmap the memory region and disassociate this object from the file.

The file handle associated with the file that is mapped is only closed if the mapping was created using a file path. If, on the other hand, an existing file handle was used to create the mapping, the file handle is not closed.

Friends And Related Symbol Documentation

◆ operator!=

template<access_mode AccessMode, typename ByteT >
bool operator!= ( const basic_shared_mmap< AccessMode, ByteT > &  a,
const basic_shared_mmap< AccessMode, ByteT > &  b 
)
friend

◆ operator<

template<access_mode AccessMode, typename ByteT >
bool operator< ( const basic_shared_mmap< AccessMode, ByteT > &  a,
const basic_shared_mmap< AccessMode, ByteT > &  b 
)
friend

◆ operator<=

template<access_mode AccessMode, typename ByteT >
bool operator<= ( const basic_shared_mmap< AccessMode, ByteT > &  a,
const basic_shared_mmap< AccessMode, ByteT > &  b 
)
friend

◆ operator==

template<access_mode AccessMode, typename ByteT >
bool operator== ( const basic_shared_mmap< AccessMode, ByteT > &  a,
const basic_shared_mmap< AccessMode, ByteT > &  b 
)
friend

All operators compare the underlying basic_mmap's addresses.

◆ operator>

template<access_mode AccessMode, typename ByteT >
bool operator> ( const basic_shared_mmap< AccessMode, ByteT > &  a,
const basic_shared_mmap< AccessMode, ByteT > &  b 
)
friend

◆ operator>=

template<access_mode AccessMode, typename ByteT >
bool operator>= ( const basic_shared_mmap< AccessMode, ByteT > &  a,
const basic_shared_mmap< AccessMode, ByteT > &  b 
)
friend

The documentation for this class was generated from the following file: