{"id":26167498,"url":"https://github.com/raftlib/shm","last_synced_at":"2025-04-14T17:43:38.872Z","repository":{"id":33955734,"uuid":"37684847","full_name":"RaftLib/shm","owner":"RaftLib","description":null,"archived":false,"fork":false,"pushed_at":"2024-12-22T14:53:27.000Z","size":1067,"stargazers_count":9,"open_issues_count":0,"forks_count":4,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-14T17:43:34.425Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RaftLib.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-06-18T21:02:20.000Z","updated_at":"2025-01-30T15:58:00.000Z","dependencies_parsed_at":"2025-03-11T17:42:41.294Z","dependency_job_id":"a65eab3d-fe57-4ee7-8572-7c3b5f253170","html_url":"https://github.com/RaftLib/shm","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RaftLib%2Fshm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RaftLib%2Fshm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RaftLib%2Fshm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RaftLib%2Fshm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RaftLib","download_url":"https://codeload.github.com/RaftLib/shm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248930090,"owners_count":21184950,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-11T17:37:58.615Z","updated_at":"2025-04-14T17:43:38.836Z","avatar_url":"https://github.com/RaftLib.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Description\nEasy SHM library for C++, still a work in progress but it's \na easier way to code up an anonymous SHM mapping, protect\nthe last page and generate a key to access it....I've used\nsimilar code quite a bit and was tired of re-coding it.  If\nI find time I'll make it a bit more advanced, like adding\na monitor process to cleanup if for some reason the code\ncrashes (you know, things happen right?).  I've tested the\ncode on OS X and Linux, but as usual your mileage may vary\ngreatly.\n\n# Build Status\n![CI](https://github.com/RaftLib/shm/workflows/CI/badge.svg)\n\n# Important Notes\nSo I've checked the functions found in the testsuite.  I've\nused the code quite a bit in various forms so it should work\nrather well...however if you find bugs please submit a pull\nrequest and I'll get it fixed ASAP.\n\n# Compilation Notes\nTo build this library on OS X you'll need to run:\n```bash\nmkdir build\ncd build\ncmake ../build -G\u003cbuild system of your choice\u003e -DCMAKE_BUILD_TYPE=Release\n[make | ninja]\n[make | ninja] test\n```\n\n## Build options\n* There are the usual options (e.g., Release/Debug), there's also...\n* ```-DUSE_SYSV_MEMORY=1``` which will build the library using the SystemV SHM interface\n* ```-DUSE_POSIX_SHM=1``` which will build the library using the POSIX SHM interface\n* ```-DCPP_EXCEPTIONS=0``` which will remove the use of CPP exceptions, the return\nvalues in this case must be checked (e.g., check for _nullptr_ vs. waiting for the \ncpp exception. \n\n# Install\n* Just run ```[make | ninja] install```\n\n\n# Usage\nTo use this library, simply:\n```cpp\n#include \u003cshm\u003e\n```\n\nWhen compiling your code that uses it, link with -lshm.  On \nLinux you'll have to compile with the -lrt, -lpthread and \n-lnuma in order to fully utilize all the features.  In \nthe future I might add a flag to compile without the NUMA\nfeatures so that you can use the library without having \nto install libnuma.\n\n## Two process example\n\n```cpp\n   shm_key_t key;\n   shm::gen_key( key, 42);\n   \n   using type_t = std::uint32_t;\n\n\n   type_t *ptr( nullptr );\n \n   /**\n    * NOTE: you can compile with or without CPP exceptions.\n    */\n   try\n   {\n      ptr = reinterpret_cast\u003c type_t* \u003e( shm::init( key, 0x1000, false, nullptr ) );\n   }\n   catch( bad_shm_alloc ex )\n   {\n      std::cerr \u003c\u003c ex.what() \u003c\u003c \"\\n\";\n      exit( EXIT_FAILURE );\n   }\n   \n    auto child = fork();\n    switch( child )\n    {\n        case( 0 /** child **/ ):\n        {   \n            try\n            {\n                ptr = shm::eopen\u003c type_t \u003e( key );\n            }\n            catch( bad_shm_alloc ex )\n            {\n                std::cerr \u003c\u003c ex.what() \u003c\u003c \"\\n\";\n                exit( EXIT_FAILURE );\n            }\n            *ptr = 0x1137;\n            shm::close( key, \n                        reinterpret_cast\u003cvoid**\u003e( \u0026ptr), \n                        0x1000,\n                        false /** don't zero   **/,\n                        false /** don't unlink **/ );\n        }\n        break;\n        case( -1 /** error, back to parent **/ ):\n        {\n            exit( EXIT_FAILURE );\n        }\n        break;\n        default:\n        {\n            /**\n             * spin on value being written from child\n             * process.\n             */\n            while( *ptr != 0x1137 ); \n            std::fprintf( stdout, \"leet\\n\" );\n            int status = 0;\n            waitpid( -1, \u0026status, 0 );\n            shm::close( key, \n                        reinterpret_cast\u003cvoid**\u003e( \u0026ptr), \n                        0x1000,\n                        true    /** zero   **/,\n                        true    /** unlink **/ );\n        }\n    }\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fraftlib%2Fshm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fraftlib%2Fshm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fraftlib%2Fshm/lists"}