Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shirasawasama/javasharedmemory
Shared memory between Java and C++/Rust/Go processes.
https://github.com/shirasawasama/javasharedmemory
cpp ffi interprocess interprocess-communication ipc java java-19 pure-java shared-memory
Last synced: about 1 month ago
JSON representation
Shared memory between Java and C++/Rust/Go processes.
- Host: GitHub
- URL: https://github.com/shirasawasama/javasharedmemory
- Owner: ShirasawaSama
- License: mit
- Created: 2023-01-23T18:34:57.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2024-03-16T06:39:00.000Z (9 months ago)
- Last Synced: 2024-04-16T14:13:17.838Z (8 months ago)
- Topics: cpp, ffi, interprocess, interprocess-communication, ipc, java, java-19, pure-java, shared-memory
- Language: Java
- Homepage:
- Size: 85 KB
- Stars: 18
- Watchers: 4
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# JavaSharedMemory [![Jitpack](https://www.jitpack.io/v/ShirasawaSama/JavaSharedMemory.svg)](https://www.jitpack.io/#ShirasawaSama/JavaSharedMemory)
Shared memory between processes. (Java, C++, Rust, etc.) Based on Java 19 [Foreign Function & Memory API](https://openjdk.org/jeps/434)
Support Windows *(CreateFileMapping)*, Linux and macOS *(mmap and shmget)*.
> **Note**
> Compared with standard input and output (anonymous pipes) on Windows, more than 2x performance improvement.## Usage
### Java
```groovy
repositories {
maven { url 'https://www.jitpack.io' }
}dependencies {
implementation 'com.github.ShirasawaSama:JavaSharedMemory:'
}tasks.withType(JavaCompile).each {
it.options.compilerArgs.add('--enable-preview')
}// kotlin script
// tasks.withType {
// options.compilerArgs = options.compilerArgs + listOf("--enable-preview")
// }
``````java
import cn.apisium.shm;public class Main {
public static void main(String[] args) {
// var shm = SharedMemory.open("test", 1024)
try (var shm = SharedMemory.create("test", 1024)) {
var buf = shm.toByteBuffer();
buf.put("Hello, World!".getBytes());
}
}
}
```### C++
```bash
git submodule add https://github.com/ShirasawaSama/JavaSharedMemory.git
```CMakeLists.txt:
```CMakeLists.txt
add_subdirectory(JavaSharedMemory)
target_link_libraries(${PROJECT_NAME} java_shared_memory)
```main.cpp:
```cpp
#includeint main() {
auto shm = jshm::shared_memory::create("test", 1024);
// auto shm = jshm::shared_memory::open("test", 1024);
strcpy((char*)shm->address(), "Hello, World!");
delete shm;
}
```## Author
Shirasawa
## License
[MIT](LICENSE)