MMU

README
Login

README

MMU is a small utility library that provides abstractions over memory mapped files.

Installation

To build MMU from source you will need a C++14 compiler and CMake.

Usage

MMU offers the following utilities:

Here's a simple usage example to get you started:

#include <cstdio>
#include <string>
#include <algorithm>
#include <MMU/MMU.hpp>

int main(int nargs, const char **args) {
  MMU::set_program_name(nargs > 0 ? args[0] : __FUNCTION__);
# if defined(__EXCEPTIONS)
  try
# endif
  {
    auto array = MMU::file_array<const char>(__FILE__);
    MMU_ASSERT(array.contiguous());
    MMU_ASSERT(array.begin() != array.end());

    auto slice = array.slice(1, 7, 2);
    MMU_ASSERT(!slice.contiguous());
    MMU_ASSERT(std::equal(slice.begin(), slice.end(), "icue<sd"));

    typedef std::basic_string<
      char, std::char_traits<char>,
      MMU::Allocator<char>
    > mmu_string_t;
    auto pool = MMU::buffer_pool("buffer_pool.d");
    mmu_string_t hello("Hello world!", pool);
    MMU_ASSERT(hello[6] == 'w');

    auto libc = MMU::shared_library(nullptr);
    auto puts = libc->get<void, const char *>("puts");
    if (MMU_UNLIKELY(!puts)) MMU_ASSERT_ERROR(libc->last_error());
    puts(hello.c_str());

    return 0;
  }
# if defined(__EXCEPTIONS)
  catch (const std::exception &exn) {
    fprintf(stderr, "%s: Error: %s\n", MMU::program_name(), exn.what());
    return 1;
  }
# endif
}