Boost  v1.57.0
doxygen for www.boost.org
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
boost::interprocess::mapped_region Class Reference

The mapped_region class represents a portion or region created from a memory_mappable object. More...

#include <mapped_region.hpp>

Public Types

enum  advice_types {
  advice_normal,
  advice_sequential,
  advice_random,
  advice_willneed,
  advice_dontneed
}
 This enum specifies region usage behaviors that an application can specify to the mapped region implementation. More...
 

Public Member Functions

template<class MemoryMappable >
 mapped_region (const MemoryMappable &mapping, mode_t mode, offset_t offset=0, std::size_t size=0, const void *address=0, map_options_t map_options=default_map_options)
 Creates a mapping region of the mapped memory "mapping", starting in offset "offset", and the mapping's size will be "size". More...
 
 mapped_region ()
 Default constructor. More...
 
 mapped_region (BOOST_RV_REF(mapped_region) other)
 Move constructor. More...
 
 ~mapped_region ()
 Destroys the mapped region. More...
 
mapped_regionoperator= (BOOST_RV_REF(mapped_region) other)
 Move assignment. More...
 
void swap (mapped_region &other)
 Swaps the mapped_region with another mapped region. More...
 
std::size_t get_size () const
 Returns the size of the mapping. Never throws. More...
 
void * get_address () const
 Returns the base address of the mapping. More...
 
mode_t get_mode () const
 Returns the mode of the mapping used to construct the mapped region. More...
 
bool flush (std::size_t mapping_offset=0, std::size_t numbytes=0, bool async=true)
 Flushes to the disk a byte range within the mapped memory. More...
 
bool shrink_by (std::size_t bytes, bool from_back=true)
 Shrinks current mapped region. More...
 
bool advise (advice_types advise)
 Advises the implementation on the expected behavior of the application with respect to the data in the region. More...
 

Static Public Member Functions

static std::size_t get_page_size ()
 Returns the size of the page. More...
 

Friends

class ipcdetail::interprocess_tester
 
class ipcdetail::raw_mapped_region_creator
 

Detailed Description

The mapped_region class represents a portion or region created from a memory_mappable object.

The OS can map a region bigger than the requested one, as region must be multiple of the page size, but mapped_region will always refer to the region specified by the user.

Member Enumeration Documentation

This enum specifies region usage behaviors that an application can specify to the mapped region implementation.

Enumerator
advice_normal 

Specifies that the application has no advice to give on its behavior with respect to the region.

It is the default characteristic if no advice is given for a range of memory.

advice_sequential 

Specifies that the application expects to access the region sequentially from lower addresses to higher addresses.

The implementation can lower the priority of preceding pages within the region once a page have been accessed.

advice_random 

Specifies that the application expects to access the region in a random order, and prefetching is likely not advantageous.

advice_willneed 

Specifies that the application expects to access the region in the near future.

The implementation can prefetch pages of the region.

advice_dontneed 

Specifies that the application expects that it will not access the region in the near future.

The implementation can unload pages within the range to save system resources.

Constructor & Destructor Documentation

template<class MemoryMappable >
boost::interprocess::mapped_region::mapped_region ( const MemoryMappable &  mapping,
mode_t  mode,
offset_t  offset = 0,
std::size_t  size = 0,
const void *  address = 0,
map_options_t  map_options = default_map_options 
)
inline

Creates a mapping region of the mapped memory "mapping", starting in offset "offset", and the mapping's size will be "size".

The mapping can be opened for read only, read-write or copy-on-write.

If an address is specified, both the offset and the address must be multiples of the page size.

The map is created using "default_map_options". This flag is OS dependant and it should not be changed unless the user needs to specify special options.

In Windows systems "map_options" is a DWORD value passed as "dwDesiredAccess" to "MapViewOfFileEx". If "default_map_options" is passed it's initialized to zero. "map_options" is XORed with FILE_MAP_[COPY|READ|WRITE].

In UNIX systems and POSIX mappings "map_options" is an int value passed as "flags" to "mmap". If "default_map_options" is specified it's initialized to MAP_NOSYNC if that option exists and to zero otherwise. "map_options" XORed with MAP_PRIVATE or MAP_SHARED.

In UNIX systems and XSI mappings "map_options" is an int value passed as "shmflg" to "shmat". If "default_map_options" is specified it's initialized to zero. "map_options" is XORed with SHM_RDONLY if needed.

The OS could allocate more pages than size/page_size(), but get_address() will always return the address passed in this function (if not null) and get_size() will return the specified size.

References BOOST_INTERPROCESS_MAP_NOSYNC, boost::interprocess::busy_error, boost::serialization::void_cast_detail::m_base, boost::math::concepts::mode(), boost::interprocess::mode_error, boost::size(), boost::interprocess::size_error, and boost::interprocess::system_error_code().

boost::interprocess::mapped_region::mapped_region ( )
inline

Default constructor.

Address will be 0 (nullptr). Size will be 0. Does not throw

boost::interprocess::mapped_region::mapped_region ( BOOST_RV_REF(mapped_region other)
inline

Move constructor.

*this will be constructed taking ownership of "other"'s region and "other" will be left in default constructor state.

References swap().

boost::interprocess::mapped_region::~mapped_region ( )
inline

Destroys the mapped region.

Does not throw

Member Function Documentation

bool boost::interprocess::mapped_region::advise ( advice_types  advise)
inline

Advises the implementation on the expected behavior of the application with respect to the data in the region.

The implementation may use this information to optimize handling of the region data. This function has no effect on the semantics of access to memory in the region, although it may affect the performance of access. If the advise type is not known to the implementation, the function returns false. True otherwise.

References advice_dontneed, advice_normal, advice_random, advice_sequential, advice_willneed, and boost::detail::void.

bool boost::interprocess::mapped_region::flush ( std::size_t  mapping_offset = 0,
std::size_t  numbytes = 0,
bool  async = true 
)
inline

Flushes to the disk a byte range within the mapped memory.

If 'async' is true, the function will return before flushing operation is completed If 'async' is false, function will return once data has been written into the underlying device (i.e., in mapped files OS cached information is written to disk). Never throws. Returns false if operation could not be performed.

void * boost::interprocess::mapped_region::get_address ( ) const
inline

Returns the base address of the mapping.

Never throws.

References boost::serialization::void_cast_detail::m_base.

mode_t boost::interprocess::mapped_region::get_mode ( ) const
inline

Returns the mode of the mapping used to construct the mapped region.

Never throws.

std::size_t boost::interprocess::mapped_region::get_page_size ( )
inlinestatic

Returns the size of the page.

This size is the minimum memory that will be used by the system when mapping a memory mappable source and will restrict the address and the offset to map.

std::size_t boost::interprocess::mapped_region::get_size ( ) const
inline

Returns the size of the mapping. Never throws.

mapped_region& boost::interprocess::mapped_region::operator= ( BOOST_RV_REF(mapped_region other)
inline

Move assignment.

If *this owns a memory mapped region, it will be destroyed and it will take ownership of "other"'s memory mapped region.

References boost::move(), and swap().

bool boost::interprocess::mapped_region::shrink_by ( std::size_t  bytes,
bool  from_back = true 
)
inline

Shrinks current mapped region.

If after shrinking there is no longer need for a previously mapped memory page, accessing that page can trigger a segmentation fault. Depending on the OS, this operation might fail (XSI shared memory), it can decommit storage and free a portion of the virtual address space (e.g.POSIX) or this function can release some physical memory wihout freeing any virtual address space(Windows). Returns true on success. Never throws.

void boost::interprocess::mapped_region::swap ( mapped_region other)
inline

Swaps the mapped_region with another mapped region.

References boost::serialization::void_cast_detail::m_base.

Referenced by mapped_region(), operator=(), and boost::interprocess::swap().

Friends And Related Function Documentation

friend class ipcdetail::interprocess_tester
friend

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