Lunchbox  1.14.0
Multi-threaded C++ toolbox library for all application developers creating high-performance multi-threaded programs.
memoryMap.h
1 
2 /* Copyright (c) 2009-2016, Stefan Eilemann <eile@equalizergraphics.com>
3  *
4  * This library is free software; you can redistribute it and/or modify it under
5  * the terms of the GNU Lesser General Public License version 2.1 as published
6  * by the Free Software Foundation.
7  *
8  * This library is distributed in the hope that it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11  * details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this library; if not, write to the Free Software Foundation, Inc.,
15  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16  */
17 
18 #ifndef LUNCHBOX_MEMORYMAP_H
19 #define LUNCHBOX_MEMORYMAP_H
20 
21 #include <lunchbox/api.h>
22 #include <boost/noncopyable.hpp>
23 #include <iostream>
24 #include <string>
25 
26 namespace lunchbox
27 {
28 namespace detail { class MemoryMap; }
29 
36 class MemoryMap : public boost::noncopyable
37 {
38 public:
40  LUNCHBOX_API MemoryMap();
41 
47  LUNCHBOX_API explicit MemoryMap( const std::string& filename );
48 
55  LUNCHBOX_API MemoryMap( const std::string& filename, const size_t size );
56 
64  LUNCHBOX_API ~MemoryMap();
65 
76  LUNCHBOX_API const void* map( const std::string& filename );
77 
87  LUNCHBOX_API const void* remap( const std::string& filename );
88 
100  LUNCHBOX_API void* create( const std::string& filename, const size_t size );
101 
112  LUNCHBOX_API void* recreate( const std::string& filename,
113  const size_t size );
114 
116  LUNCHBOX_API void unmap();
117 
119  LUNCHBOX_API const void* getAddress() const;
120 
122  LUNCHBOX_API void* getAddress();
123 
125  template< class T > const T* getAddress() const
126  { return static_cast< const T* >( getAddress( )); }
127 
129  template< class T > T* getAddress()
130  { return static_cast< T* >( getAddress( )); }
131 
133  LUNCHBOX_API size_t getSize() const;
134 
135 private:
136  detail::MemoryMap* const impl_;
137 };
138 
139 inline std::ostream& operator << ( std::ostream& os, const MemoryMap& m )
140 {
141  return os << "MemoryMap at " << m.getAddress() << " size " << m.getSize();
142 }
143 
144 }
145 
146 #endif //LUNCHBOX_MEMORYMAP_H
Defines export visibility macros for library Lunchbox.
const void * getAddress() const
size_t getSize() const
Helper to map a file to a memory address (mmap).
Definition: memoryMap.h:36
Abstraction layer and common utilities for multi-threaded programming.
Definition: algorithm.h:32
std::ostream & operator<<(std::ostream &os, const Array< T > &array)
Pretty-print all members of the array.
Definition: array.h:47
const T * getAddress() const
Definition: memoryMap.h:125