Osmium  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes
Osmium::Storage::Mmap< TValue > Class Template Reference

#include <byid.hpp>

Inheritance diagram for Osmium::Storage::Mmap< TValue >:
Inheritance graph
[legend]
Collaboration diagram for Osmium::Storage::Mmap< TValue >:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Mmap ()
 Mmap (std::string &filename, bool remove=true)
 ~Mmap ()
void set (uint64_t id, TValue value)
 Set the field with id to value.
const TValue & operator[] (uint64_t id) const
 Retrieve value by key. Does not check for overflow or empty fields.
uint64_t size () const
uint64_t used_memory () const
void clear ()

Static Public Attributes

static const uint64_t size_increment = 10 * 1024 * 1024

Private Member Functions

uint64_t get_file_size ()
 Get file size in bytes.

Private Attributes

uint64_t m_size
int m_fd
TValue * m_items

Detailed Description

template<typename TValue>
class Osmium::Storage::Mmap< TValue >

The Mmap store stores location using the mmap() system call, either backed by a file on disk or just in-memory. It will grow automatically.

If you have enough memory it is preferred to use the in-memory version. If you don't have enough memory or want the information to persist, use the file-backed version. Note that you still need substantial amounts of memory for this to work efficiently.

Note that this storage class will only work on 64 bit systems if used for storing node coordinates. 32 bit systems just can't address that much memory!


Constructor & Destructor Documentation

template<typename TValue >
Osmium::Storage::Mmap< TValue >::Mmap ( ) [inline]

Create anonymous mapping without a backing file.

Exceptions:
std::bad_allocThrown when there is not enough memory.
template<typename TValue >
Osmium::Storage::Mmap< TValue >::Mmap ( std::string &  filename,
bool  remove = true 
) [inline]

Create mapping backed by file. If filename is empty, a temporary file will be created.

Parameters:
filenameThe filename (including the path) for the storage.
removeShould the file be removed after use?
Exceptions:
std::bad_allocThrown when there is not enough memory or some other problem.
template<typename TValue >
Osmium::Storage::Mmap< TValue >::~Mmap ( ) [inline]

Member Function Documentation

template<typename TValue >
void Osmium::Storage::Mmap< TValue >::clear ( ) [inline, virtual]

Clear memory used for this storage. After this you can not use the storage container any more.

Implements Osmium::Storage::ById< TValue >.

template<typename TValue >
uint64_t Osmium::Storage::Mmap< TValue >::get_file_size ( ) [inline, private]

Get file size in bytes.

template<typename TValue >
const TValue& Osmium::Storage::Mmap< TValue >::operator[] ( uint64_t  id) const [inline, virtual]

Retrieve value by key. Does not check for overflow or empty fields.

Implements Osmium::Storage::ById< TValue >.

template<typename TValue >
void Osmium::Storage::Mmap< TValue >::set ( uint64_t  id,
TValue  value 
) [inline, virtual]

Set the field with id to value.

Implements Osmium::Storage::ById< TValue >.

template<typename TValue >
uint64_t Osmium::Storage::Mmap< TValue >::size ( ) const [inline, virtual]

Get the approximate number of items in the storage. The storage might allocate memory in blocks, so this size might not be accurate. You can not use this to find out how much memory the storage uses. Use used_memory() for that.

Implements Osmium::Storage::ById< TValue >.

template<typename TValue >
uint64_t Osmium::Storage::Mmap< TValue >::used_memory ( ) const [inline, virtual]

Get the memory used for this storage in bytes. Note that this is not necessarily entirely accurate but an approximation. For storage classes that store the data in memory, this is the main memory used, for storage classes storing data on disk this is the memory used on disk.

Implements Osmium::Storage::ById< TValue >.


Member Data Documentation

template<typename TValue >
int Osmium::Storage::Mmap< TValue >::m_fd [private]
template<typename TValue >
TValue* Osmium::Storage::Mmap< TValue >::m_items [private]
template<typename TValue >
uint64_t Osmium::Storage::Mmap< TValue >::m_size [private]
template<typename TValue >
const uint64_t Osmium::Storage::Mmap< TValue >::size_increment = 10 * 1024 * 1024 [static]

The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines