Libosmium: osmium::util::TypedMemoryMapping< T > Class Template Reference

Libosmium Fast and flexible C++ library for working with OpenStreetMap data

Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
osmium::util::TypedMemoryMapping< T > Class Template Reference

`#include <memory_mapping.hpp>`

Inheritance diagram for osmium::util::TypedMemoryMapping< T >:
[legend]
Collaboration diagram for osmium::util::TypedMemoryMapping< T >:
[legend]

## Public Member Functions
| TypedMemoryMapping (std::size_t size)
| TypedMemoryMapping (std::size_t size, MemoryMapping::mapping_mode mode, int fd, off_t offset=0)
| TypedMemoryMapping (const TypedMemoryMapping &)=delete
| You can not copy construct a TypedMemoryMapping.
TypedMemoryMapping & | operator= (const TypedMemoryMapping &)=delete
| You can not copy a TypedMemoryMapping.
| TypedMemoryMapping (TypedMemoryMapping &&other) noexcept=default
TypedMemoryMapping & | operator= (TypedMemoryMapping &&other) noexcept=default
| ~TypedMemoryMapping () noexcept=default
void | unmap ()
void | resize (std::size_t new_size)
| operator bool () const noexcept
std::size_t | size () const noexcept
int | fd () const noexcept
bool | writable () const noexcept
T * | begin () noexcept
T * | end () noexcept
const T * | cbegin () const noexcept
const T * | cend () const noexcept
const T * | begin () const noexcept
const T * | end () const noexcept

## Private Attributes
MemoryMapping | m_mapping

## Detailed Description

template<typename T>
class osmium::util::TypedMemoryMapping< T >

A thin wrapper around the MemoryMapping class used when all the data in the mapped memory is of the same type. Instead of thinking about the number of bytes mapped, this counts sizes in the number of objects of that type.

Note that no effort is made to actually initialize the objects in this memory. This has to be done by the caller!

## Constructor & Destructor Documentation

## ◆ TypedMemoryMapping() [1/4]

template<typename T>

osmium::util::TypedMemoryMapping< T >::TypedMemoryMapping | ( | std::size_t | size | ) |
| inlineexplicit

Create anonymous typed memory mapping of given size.

Parameters

  size | Number of objects of type T to be mapped

Exceptions

  std::system_error | if the mapping fails

## ◆ TypedMemoryMapping() [2/4]

template<typename T>

osmium::util::TypedMemoryMapping< T >::TypedMemoryMapping | ( | std::size_t | size,
|  | MemoryMapping::mapping_mode | mode,
|  | int | fd,
|  | off_t | offset = 0 )
| inline

Create file-backed memory mapping of given size. The file must contain at least sizeof(T) * size bytes!

Parameters

  size | Number of objects of type T to be mapped
  mode | Mapping mode: readonly, or writable (shared or private)
  fd | Open file descriptor of a file we want to map
  offset | Offset into the file where the mapping should start

Exceptions

  std::system_error | if the mapping fails

## ◆ TypedMemoryMapping() [3/4]

template<typename T>

osmium::util::TypedMemoryMapping< T >::TypedMemoryMapping | ( | const TypedMemoryMapping< T > & |  | ) |
| delete

You can not copy construct a TypedMemoryMapping.

## ◆ TypedMemoryMapping() [4/4]

template<typename T>

osmium::util::TypedMemoryMapping< T >::TypedMemoryMapping | ( | TypedMemoryMapping< T > && | other | ) |
| defaultnoexcept

Move construct a mapping from another one. The other mapping will be marked as invalid.

## ◆ ~TypedMemoryMapping()

template<typename T>

osmium::util::TypedMemoryMapping< T >::~TypedMemoryMapping | ( |  | ) |
| defaultnoexcept

Releases the mapping by calling unmap(). Will never throw. Call unmap() instead if you want to be notified of any error.

## Member Function Documentation

## ◆ begin() [1/2]

template<typename T>

const T * osmium::util::TypedMemoryMapping< T >::begin | ( |  | ) | const
| inlinenoexcept

Get the address of the beginning of the mapping.

Precondition
  is_valid()

## ◆ begin() [2/2]

template<typename T>

T * osmium::util::TypedMemoryMapping< T >::begin | ( |  | ) |
| inlinenoexcept

Get the address of the beginning of the mapping.

Precondition
  is_valid()

## ◆ cbegin()

template<typename T>

const T * osmium::util::TypedMemoryMapping< T >::cbegin | ( |  | ) | const
| inlinenoexcept

Get the address of the beginning of the mapping.

Precondition
  is_valid()

## ◆ cend()

template<typename T>

const T * osmium::util::TypedMemoryMapping< T >::cend | ( |  | ) | const
| inlinenoexcept

Get the address one past the end of the mapping.

Precondition
  is_valid()

## ◆ end() [1/2]

template<typename T>

const T * osmium::util::TypedMemoryMapping< T >::end | ( |  | ) | const
| inlinenoexcept

Get the address one past the end of the mapping.

Precondition
  is_valid()

## ◆ end() [2/2]

template<typename T>

T * osmium::util::TypedMemoryMapping< T >::end | ( |  | ) |
| inlinenoexcept

Get the address one past the end of the mapping.

Precondition
  is_valid()

## ◆ fd()

template<typename T>

int osmium::util::TypedMemoryMapping< T >::fd | ( |  | ) | const
| inlinenoexcept

The file descriptor this mapping was created from.

Returns
  file descriptor, -1 for anonymous mappings

## ◆ operator bool()

template<typename T>

osmium::util::TypedMemoryMapping< T >::operator bool | ( |  | ) | const
| inlineexplicitnoexcept

In a boolean context a TypedMemoryMapping is true when it is a valid existing mapping.

## ◆ operator=() [1/2]

template<typename T>

TypedMemoryMapping & osmium::util::TypedMemoryMapping< T >::operator= | ( | const TypedMemoryMapping< T > & |  | ) |
| delete

You can not copy a TypedMemoryMapping.

## ◆ operator=() [2/2]

template<typename T>

TypedMemoryMapping & osmium::util::TypedMemoryMapping< T >::operator= | ( | TypedMemoryMapping< T > && | other | ) |
| defaultnoexcept

Move a mapping. The other mapping will be marked as invalid.

## ◆ resize()

template<typename T>

void osmium::util::TypedMemoryMapping< T >::resize | ( | std::size_t | new_size | ) |
| inline

Resize a mapping to the given new size.

On Linux systems this will use the mremap() function. On other systems it will unmap and remap the memory. This can only be done for file-based mappings, not anonymous mappings!

Parameters

  new_size | Number of objects of type T to resize to

Exceptions

  std::system_error | if the remapping fails

## ◆ size()

template<typename T>

std::size_t osmium::util::TypedMemoryMapping< T >::size | ( |  | ) | const
| inlinenoexcept

The number of objects of class T mapped. This is the same size you created the mapping with. The actual mapping will probably be larger because the system will round it to the page size.

## ◆ unmap()

template<typename T>

void osmium::util::TypedMemoryMapping< T >::unmap | ( |  | ) |
| inline

Unmap a mapping. If the mapping is not valid, it will do nothing.

Exceptions

  std::system_error | if the unmapping fails

## ◆ writable()

template<typename T>

bool osmium::util::TypedMemoryMapping< T >::writable | ( |  | ) | const
| inlinenoexcept

Was this mapping created as a writable mapping?

## Member Data Documentation

## ◆ m_mapping

template<typename T>

MemoryMapping osmium::util::TypedMemoryMapping< T >::m_mapping
| private

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

- include/osmium/util/memory_mapping.hpp