Documentation
¶
Overview ¶
Example: sharedmem package overview
The ndk/sharedmem package provides Go bindings for Android's ASharedMemory API (available since API level 26).
ASharedMemory enables creating and managing anonymous shared memory regions that can be shared between processes via file descriptors. This is useful for zero-copy IPC, large data transfers between services, and sharing buffers with the Android framework.
Typical workflow:
- Create a shared memory region: ASharedMemory_create(name, size)
- Get the file descriptor for sharing
- Map into process address space with mmap()
- Share the fd with another process (via Binder/socket)
- The other process mmaps the same fd
- Both processes read/write the shared region
- Set protection with ASharedMemory_setProt() to make read-only
The underlying ASharedMemory functions operate on file descriptors (int), not opaque handles.
This program must run on an Android device with API level 26+.
Click to show internal directories.
Click to hide internal directories.