Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of boost. Click here for the latest Boost documentation.
PrevUpHomeNext

Class mapped_region

boost::interprocess::mapped_region

Synopsis

// In header: <boost/interprocess/mapped_region.hpp>


class mapped_region {
public:
  enum advice_types;
  // construct/copy/destruct
  template<typename MemoryMappable> 
    mapped_region(const MemoryMappable &, mode_t, offset_t = 0, 
                  std::size_t = 0, const void * = 0);
  mapped_region();
  mapped_region(BOOST_RV_REF(mapped_region));
  mapped_region& operator=(BOOST_RV_REF(mapped_region));
  ~mapped_region();

  // public member functions
  void swap(mapped_region &);
  std::size_t get_size() const;
  void * get_address() const;
  mode_t get_mode() const;
  bool flush(std::size_t = 0, std::size_t = 0, bool = true);
  bool shrink_by(std::size_t, bool = true);
  bool advise(advice_types);

  // public static functions
  static std::size_t get_page_size();
};

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.

mapped_region public construct/copy/destruct

  1. template<typename MemoryMappable> 
      mapped_region(const MemoryMappable & mapping, mode_t mode, 
                    offset_t offset = 0, std::size_t size = 0, 
                    const void * address = 0);

    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 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.

  2. mapped_region();

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

  3. mapped_region(BOOST_RV_REF(mapped_region) other);

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

  4. mapped_region& operator=(BOOST_RV_REF(mapped_region) other);

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

  5. ~mapped_region();

    Destroys the mapped region. Does not throw

mapped_region public member functions

  1. void swap(mapped_region & other);

    Swaps the mapped_region with another mapped region

  2. std::size_t get_size() const;
    Returns the size of the mapping. Never throws.
  3. void * get_address() const;

    Returns the base address of the mapping. Never throws.

  4. mode_t get_mode() const;

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

  5. 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. 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.

  6. bool shrink_by(std::size_t bytes, bool from_back = true);

    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.

  7. bool advise(advice_types advise);

    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.

mapped_region public static functions

  1. static std::size_t get_page_size();

    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.


PrevUpHomeNext