A collection of examples demonstrating zero-copy shared memory communication between processes on macOS.
This repository contains examples of inter-process communication using zero-copy shared memory on macOS. The examples demonstrate different approaches to shared memory:
- POSIX shared memory (shm_open) with memory mapping
- Memory-mapped files (mmap) for persistent storage
- Lock-free synchronization with atomic operations
- SIMD-accelerated processing with Apple Silicon optimizations
Each approach has different performance characteristics and use cases.
A simple demonstration where one process counts down from 10 to 0, sending each number to another process that processes it. Uses POSIX shared memory (shm_open) and semaphores for synchronization.
An example of continuous data streaming between processes. One process generates random X,Y coordinates and the other displays them in real-time. Uses POSIX shared memory (shm_open) and semaphores for synchronization.
A high-performance lock-free ring buffer implementation using atomic operations for thread-safe communication without mutexes. Demonstrates efficient producer-consumer pattern with non-blocking I/O. Uses POSIX shared memory (shm_open) but replaces semaphores with atomic operations.
A persistent shared memory example using memory-mapped files (mmap) with regular files. Demonstrates how to create a simple database that persists between program executions and can be accessed by multiple processes simultaneously. Uses pthread mutexes for synchronization.
A high-performance example optimized for Apple Silicon (M-series) processors. Uses SIMD vector instructions (ARM NEON) to process data in parallel, huge pages for better TLB efficiency, and cache-line alignment to prevent false sharing. Demonstrates how to achieve maximum performance on modern hardware.
A benchmark comparing standard buffer processing against SIMD-accelerated processing.
This repository uses Git submodules for external dependencies. To clone the repository with all submodules:
# Clone the repository with submodules
git clone --recursive https://github.com/pjsny/macos-zero-copy-ipc.git
# Or if you already cloned without --recursive:
git submodule init
git submodule update
# Build all examples
make
# Build a specific example
make countdown
make buffer_transfer
make ring_buffer
make mmap_file
make simd_processing
make benchmark_simd
The SIMD-Accelerated Processing example uses the math_intrinsics library by Geolm for efficient SIMD math operations. This excellent library provides transcendental math functions (cos, sin, acos, etc.) implemented using 100% AVX/Neon instructions with no branching.