|
| 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, size_t size) |
| Recreate a different writable file for this memory map. More...
|
|
void * | resize (size_t size) |
| Resize a writeable 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 () |
|
template<class T > |
T & | get (const size_t i) |
| Access the given element in the map. More...
|
|
template<class T > |
const T & | get (const size_t i) const |
| Access the given element in the map. More...
|
|
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 <boost/test/unit_test.hpp>
#include <lunchbox/memoryMap.h>
#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 / 2));
uint8_t* writePtr =
map.getAddress<uint8_t>();
BOOST_CHECK(writePtr);
size_t i = 0;
for (; i < MAP_SIZE / 2; i += STRIDE)
writePtr[i] = uint8_t(i);
BOOST_CHECK(
map.resize(MAP_SIZE));
writePtr =
map.getAddress<uint8_t>();
for (; 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 (i = 0; i < MAP_SIZE; i += STRIDE)
BOOST_CHECK_EQUAL(readPtr[i], uint8_t(i));
}
BOOST_AUTO_TEST_CASE(exceptions)
{
std::runtime_error);
}
Definition at line 39 of file memoryMap.h.