79 lines
1.6 KiB
Markdown
79 lines
1.6 KiB
Markdown
# shmcpp
|
|
|
|
A modern C++20 cross-platform shared memory library with RAII resource management.
|
|
|
|
## Features
|
|
|
|
- Cross-platform support (Windows/POSIX)
|
|
- Modern C++20 with concepts
|
|
- Automatic resource cleanup via RAII
|
|
- Type-safe interface
|
|
|
|
## Requirements
|
|
|
|
- C++20 compatible compiler
|
|
- CMake 4.0 or higher
|
|
|
|
## Building
|
|
|
|
```bash
|
|
mkdir build && cd build
|
|
cmake ..
|
|
cmake --build .
|
|
```
|
|
|
|
## Quick Start
|
|
|
|
```cpp
|
|
#include <shmcpp/shared_memory.hpp>
|
|
|
|
// Create shared memory
|
|
auto shm = shmcpp::SharedMemory::create("my_shm", 1024);
|
|
|
|
// Open existing shared memory
|
|
auto shm = shmcpp::SharedMemory::open("my_shm");
|
|
|
|
// Map memory region
|
|
auto view = shm.map(0, 1024);
|
|
|
|
// Get size
|
|
std::size_t size = shm.size();
|
|
```
|
|
|
|
> **Note:** Direct memory access APIs are not provided. Data structures for safe memory operations will be implemented in future releases.
|
|
|
|
## API Overview
|
|
|
|
### SharedMemory
|
|
|
|
- `static SharedMemory create(const std::string& name, std::size_t size)`
|
|
- Creates a new shared memory region
|
|
|
|
- `static SharedMemory open(const std::string& name)`
|
|
- Opens an existing shared memory region
|
|
|
|
- `MappedView map(std::size_t offset, std::size_t length)`
|
|
- Maps a memory region for access
|
|
|
|
- `std::size_t size() const noexcept`
|
|
- Returns the size of shared memory
|
|
|
|
### MappedView
|
|
|
|
- RAII wrapper for mapped memory region
|
|
- Automatically unmaps on destruction
|
|
- Move-only type (non-copyable)
|
|
|
|
## Platform Support
|
|
|
|
- **Windows**: Win32 API (CreateFileMapping/MapViewOfFile)
|
|
- **Linux/Unix**: POSIX shared memory (shm_open/mmap)
|
|
|
|
## Integration
|
|
|
|
Link against the `shmcpp` static library:
|
|
|
|
```cmake
|
|
target_link_libraries(your_target PRIVATE shmcpp)
|
|
```
|