|
| MemoryMap () |
| Construct a new memory map. More...
|
|
| MemoryMap (const std::string &filename) |
| Construct and initialize a new, readonly memory map. More...
|
|
| MemoryMap (const std::string &filename, const size_t size) |
| Construct and initialize a new, read-write memory map. More...
|
|
| ~MemoryMap () |
| Destruct the memory map. More...
|
|
const void * | map (const std::string &filename) |
| Map a file to a memory address. More...
|
|
const void * | remap (const std::string &filename) |
| Remap a different file for this memory map. More...
|
|
void * | create (const std::string &filename, const size_t size) |
| Create a writable file to a memory address. More...
|
|
void * | recreate (const std::string &filename, const size_t size) |
| Recreate a different writable file for this memory map. More...
|
|
void | unmap () |
| Unmap the file. More...
|
|
const void * | getAddress () const |
|
void * | getAddress () |
|
template<class T > |
const T * | getAddress () const |
|
template<class T > |
T * | getAddress () |
|
size_t | getSize () const |
|
Helper to map a file to a memory address (mmap).
- Deprecated:
- Use boost::iostreams::mapped_file_source
Example:
#define BOOST_TEST_MODULE MemoryMap
#include <lunchbox/memoryMap.h>
#include <boost/test/unit_test.hpp>
#define MAP_SIZE LB_10MB
#define STRIDE 23721
BOOST_AUTO_TEST_CASE( write_read )
{
BOOST_CHECK_EQUAL(
map.getSize(), MAP_SIZE );
BOOST_CHECK(
map.recreate(
"foo.mmap", MAP_SIZE ));
uint8_t* writePtr =
map.getAddress< uint8_t >();
BOOST_CHECK( writePtr );
for( size_t i=0; i < MAP_SIZE; i += STRIDE )
writePtr[i] = uint8_t( i );
const void* noPtr =
map.map(
"foo.map" );
BOOST_CHECK( !noPtr );
BOOST_CHECK_EQUAL(
map.getSize(), 0 );
BOOST_CHECK(
map.map(
"foo.mmap" ));
BOOST_CHECK( !
map.map(
"foo.mmap" ));
BOOST_CHECK(
map.remap(
"foo.mmap" ));
const uint8_t* readPtr =
map.getAddress< uint8_t >();
BOOST_CHECK( readPtr );
BOOST_CHECK_EQUAL(
map.getSize(), MAP_SIZE );
for( size_t i=0; i < MAP_SIZE; i += STRIDE )
BOOST_CHECK_EQUAL( readPtr[i], uint8_t( i ));
}
BOOST_AUTO_TEST_CASE( exceptions )
{
std::runtime_error );
std::runtime_error );
}
Definition at line 36 of file memoryMap.h.