npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cpp_libsharedmemory

v0.0.9

Published

C++11 header-only library for using shared memory on Windows, Linux and macOS

Downloads

5

Readme

libsharedmemory

libsharedmemory is a small C++11 header-only library for using shared memory on Windows, Linux and macOS. libsharedmemory makes it easy to transfer data between isolated host OS processes. It also helps inter-connecting modules of applications that are implemented in different programming languages. It allows for simple read/write data transfer using single, indexed memory address access and also using array-types like std::string, float*, double*.

Example


std::string dataToTransfer = "{ foo: 'coolest IPC ever! 🧑‍💻' }";

// the name of the shared memory is os-wide announced
// the size is in bytes and must be big enough to handle the data (up to 4GiB)
// if persistency is disabled, the shared memory segment will
// be garbage collected when the process that wrote it is killed
SharedMemoryWriteStream write$ {/*name*/ "jsonPipe", /*size*/ 65535, /*persistent*/ true};
SharedMemoryReadStream read$ {/*name*/ "jsonPipe", /*size*/ 65535, /*persistent*/ true};

// writing the string to the shared memory
write$.write(dataToTransfer);

// reading the string from shared memory
// you can run this in another process, thread,
// even in another app written in another programming language
std::string dataString = read$.read();

std::cout << "UTF8 string written and read" << dataString << std::endl;

Source code package management via npm

In case you want to use this library in your codebase, you could just copy & paste the include/libsharedmemory/libsharedmemory.hpp into your include or deps directory. But then you'd have to manually manage the code base.

However, you could also use npm for a smarter dependency management approach. Therefore, install Node.js which comes bundled with npm, the Node package manager.

Now run npm init in your project root directoy. After initial setup, run npm install cpp_libsharedmemory and add node_modules/cpp_libsharedmemory/include/libsharedmemory to your include path.

Whenever this library updates, you can also update your dependencies via npm upgrade. Futhermore, people who audit the code can announce security reports that are announced when running npm audit. Finally, it's also much easier for you to install all project dependencies by just running npm install in your projects root directory. Managing third party code becomes obsolete at all.

Limits

libsharedmemory does only support the following datatypes (array-like):

  • std::string
  • float*
  • double*

Single value access via .data()[index] API:

  • all scalar datatypes supported in C/C++

  • This library doesn't care for endinanness. This should be naturally fine because shared memory shouldn't be shared between different machine architectures. However, if you plan to copy the shared buffer onto a network layer prototcol, make sure to add an endianess indication bit.

  • Although the binary memory layout should give you no headache when compiling/linking using different compilers, the behavior is undefined.

  • At the time of writing, there is no support for shared memory persistency on Windows. Shared memory is lost after the writing process is killed.

Memory layout

When writing data into a named shared memory segment, libsharedmemory does write 5 bytes of meta information:

  • flags (char) is a bitmask that indicates data change (via an odd/even bit flip) as well as the data type transferred (1 byte)
  • size (int) indicates the buffer size in bytes (4 bytes)

Therefore the binary memory layout is: |flags|size|data|

The following datatype flags are defined:

enum DataType {
  kMemoryChanged = 1,
  kMemoryTypeString = 2,
  kMemoryTypeFloat = 4,
  kMemoryTypeDouble = 8,
};

kMemoryChanged is the change indicator bit. It will flip odd/evenly to indicate data change. Continuous data reader will thus be able to catch every data change.

Build

This project is meant to be built with cmake and clang. However, it should also build with MSVC and GCC.

./build.sh

Test

Test executables are built automatically and can be executed to verify the correct function of the implementation on your machine:

./test.sh

License

libsharedmemory is released under the MIT license, see the LICENSE file.

Roadmap

  1. Windows shared memory persistency support
  2. Multi-threaded non-blocking onChange( lambda fn ) data change handler on the read stream