Giter Site home page Giter Site logo

cxxshm's Introduction

CxxSHM

A C++ Library to handle POSIX shared memory

Usage

Initialize cxxshm::SharedMemory

Option A: Create Shared Memory

const std::string shm_name     = "example_shm";  // shared memory name
constexpr std::size_t shm_size = 4096;           // shared memory size
constexpr bool read_only       = false;          // allow read and write
constexpr bool exclusive       = true;           // fail if shared memory already exists
constexpr mode_t shm_mode      = 0660;           // read and write access for user and group

// create shared memory
cxxshm::SharedMemory shm(shm_name, shm_size, read_only, exclusive, shm_mode);

Option B: Connect to Existing Shared Memory

const std::string shm_name     = "example_shm";  // shared memory name
constexpr bool read_only       = false;          // allow read and write

// use shared memory
cxxshm::SharedMemory shm(shm_name, read_only);

Access Shared Memory Data

Get Pointer to Shared Memory

auto shm_data = shm.get_addr<void *>();
auto shm_data_int = shm.get_addr<int *>();

Array Access

Access element of shared memory without range check (dangerous):

const auto value = shm.operator[]<int>(1);

Access element of shared memory with range check:

const auto value = shm.at<long>(42);

Get Shared Memory Information

Get Name

const std::string& shm_name = shm.get_name();

Get Size

const std::size_t shm_size = shm.get_size();

cxxshm's People

Contributors

nikolask-source avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

savergenio

cxxshm's Issues

Test

add test cases

add tests

  • create shm
    • check size
    • already exists
    • force
  • permissions

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.