LLFIO  v2.00
llfio_v2_xxx::mapped< T > Class Template Reference

Provides an owning, typed view of memory mapped from a section_handle or a file_handle suitable for feeding to STL algorithms or the Ranges TS. More...

#include "mapped.hpp"

Inheritance diagram for llfio_v2_xxx::mapped< T >:

Public Types

using extent_type = typename section_handle::extent_type
 The extent type.
 
using size_type = typename section_handle::size_type
 The size type.
 
using element_type = typename span< T >::element_type
 The index type. More...
 
using value_type = typename span< T >::value_type
 The value type.
 
using reference = typename span< T >::reference
 The reference type.
 
using pointer = typename span< T >::pointer
 The pointer type.
 
using const_reference = typename span< T >::const_reference
 The const reference type.
 
using const_pointer = typename span< T >::const_pointer
 The const pointer type.
 
using iterator = typename span< T >::iterator
 The iterator type.
 
using reverse_iterator = typename span< T >::reverse_iterator
 The const iterator type. More...
 
using difference_type = typename span< T >::difference_type
 The const reverse iterator type. More...
 

Public Member Functions

constexpr mapped ()
 Default constructor.
 
 mapped (const mapped &)=delete
 
 mapped (mapped &&o) noexcept
 
mappedoperator= (const mapped &)=delete
 
mappedoperator= (mapped &&o) noexcept
 
 ~mapped ()
 Detaches the array of T, before tearing down the map.
 
const section_handlesection () const noexcept
 Returns a reference to the internal section handle.
 
const map_handlemap () const noexcept
 Returns a reference to the internal map handle.
 
span< T > as_span () const noexcept
 Returns a span referring to this mapped region.
 
 mapped (size_type length, bool zeroed=false, section_handle::flag _flag=section_handle::flag::readwrite)
 
 mapped (section_handle &sh, size_type length=(size_type) -1, extent_type byteoffset=0, section_handle::flag _flag=section_handle::flag::readwrite)
 
 mapped (file_handle &backing, size_type length=(size_type) -1, extent_type maximum_size=0, extent_type byteoffset=0, section_handle::flag _flag=section_handle::flag::readwrite)
 

Detailed Description

template<class T>
class llfio_v2_xxx::mapped< T >

Provides an owning, typed view of memory mapped from a section_handle or a file_handle suitable for feeding to STL algorithms or the Ranges TS.

This opens a new map_handle (and if necessary a section_handle) onto the requested offset and length of the supplied source, and thus is an owning view of mapped memory. It can be moved, but not copied.

The array of objects upon which the owning view is opened is attached via in_place_detach<T>() in the mapped constructor. In the final destructor (i.e. not the destructor of any moved-from instances), the array of objects is detached via in_place_detach<T>() just before the map_handle is destroyed. As it is illegal to attach objects into more than one address or process at a time, you must not call mapped on objects already mapped into any process anywhere else.

These owning semantics are convenient, but may be too heavy for your use case. You can gain more fine grained control using map_handle/mapped_file_handle directly with P1631 attached<T>.

Note
Only on the clang compiler, does mapped actually use P1631 in_place_attach/in_place_detach, as currently GCC and MSVC do two memcpy's of the mapped region. Also, we restrict the use of in_place_attach/in_place_detach to regions less than 4Kb in size, as even clang falls down on large regions.

Optionally can issue a blocking write barrier on destruction of the mapped view by setting the flag section_handle::flag::barrier_on_close, thus forcing any changes to data referred to by this to storage before the destructor returns.

Member Typedef Documentation

◆ difference_type

template<class T >
using llfio_v2_xxx::mapped< T >::difference_type = typename span<T>::difference_type

The const reverse iterator type.

The difference type

◆ element_type

template<class T >
using llfio_v2_xxx::mapped< T >::element_type = typename span<T>::element_type

The index type.

The element type

◆ reverse_iterator

template<class T >
using llfio_v2_xxx::mapped< T >::reverse_iterator = typename span<T>::reverse_iterator

The const iterator type.

The reverse iterator type

Constructor & Destructor Documentation

◆ mapped() [1/3]

template<class T >
llfio_v2_xxx::mapped< T >::mapped ( size_type  length,
bool  zeroed = false,
section_handle::flag  _flag = section_handle::flag::readwrite 
)
inlineexplicit

Create a view of newly allocated unused memory, creating new memory if insufficient unused memory is available. Note that the memory mapped by this call may contain non-zero bits (recycled memory) unless zeroed is true.

Parameters
lengthThe number of items to map.
zeroedWhether to ensure that the viewed memory returned is all bits zero or not.
_flagThe flags to pass to map_handle::map().
222  : _maph(map_handle::map(length * sizeof(T), zeroed, _flag).value())
223  {
224  byte *addr = _maph.address();
225  static_cast<span<T> &>(*this) = detail::attach_or_reinterpret<T>::attach({addr, length * sizeof(T)});
226  }
byte * address() const noexcept
The address in memory where this mapped view resides.
Definition: map_handle.hpp:721
static result< map_handle > map(size_type bytes, bool zeroed=false, section_handle::flag _flag=section_handle::flag::readwrite) noexcept
Definition: map_handle.hpp:633
result< section_handle::extent_type > length(const section_handle &self) noexcept
Return the current maximum permitted extent of the memory section.
Definition: map_handle.hpp:1071

◆ mapped() [2/3]

template<class T >
llfio_v2_xxx::mapped< T >::mapped ( section_handle sh,
size_type  length = (size_type) -1,
extent_type  byteoffset = 0,
section_handle::flag  _flag = section_handle::flag::readwrite 
)
inlineexplicit

Construct a mapped view of the given section handle.

Parameters
shThe section handle to use as the data source for creating the map.
lengthThe number of items to map, use -1 to mean the length of the section handle divided by sizeof(T).
byteoffsetThe byte offset into the section handle, this does not need to be a multiple of the page size.
_flagThe flags to pass to map_handle::map().
235  : mapped((length == 0) ? mapped() :
236  mapped(nullptr, 0,
237 #ifdef _WIN32
238  byteoffset & ~65535,
239 #else
241 #endif
242  byteoffset, &sh, (length == (size_type) -1) ? 0 : length * sizeof(T), _flag)) // NOLINT
243  {
244  }
typename section_handle::size_type size_type
The size type.
Definition: mapped.hpp:102
constexpr mapped()
Default constructor.
Definition: mapped.hpp:155
size_t page_size() noexcept
Returns the smallest page size of this architecture which is useful for calculating direct i/o multip...
T round_down_to_page_size(T i, size_t pagesize) noexcept
Round a value to its next lowest page size multiple.
Definition: utils.hpp:51

◆ mapped() [3/3]

template<class T >
llfio_v2_xxx::mapped< T >::mapped ( file_handle backing,
size_type  length = (size_type) -1,
extent_type  maximum_size = 0,
extent_type  byteoffset = 0,
section_handle::flag  _flag = section_handle::flag::readwrite 
)
inlineexplicit

Construct a mapped view of the given file.

Parameters
backingThe handle to use as backing storage.
lengthThe number of items to map, use -1 to mean the length of the section handle divided by sizeof(T).
maximum_sizeThe initial size of this section in bytes, which cannot be larger than any backing file. Zero means to use backing.maximum_extent().
byteoffsetThe byte offset into the section handle, this does not need to be a multiple of the page size.
_flagThe flags to pass to map_handle::map().
254  : mapped((length == 0) ? mapped() :
255  mapped(&backing, maximum_size,
256 #ifdef _WIN32
257  byteoffset & ~65535,
258 #else
260 #endif
261  byteoffset, nullptr, (length == (size_type) -1) ? 0 : length * sizeof(T), _flag)) // NOLINT
262  {
263  }

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