On Nov 4, 2:51 pm, James SDC <
hanzon...@gmail.com> wrote:
> I have tried to use shmget() and shmat() with the Android NDK 1.5_r1
> package, but I got "undefined reference" with them. I tried to search
> them from all *.h files of the package, but the PC could not find
> them.
Take a look at system/core/init/property_service.c : init_workspace()
(the system properties mechanism used by getprop/setprop). It creates
a shared memory segment on top of the ashmem mechanism. Any process
with the file descriptor can mmap() it, as happens over in bionic/libc/
bionic/system_properties.c.
That uses a file descriptor inherited from init (since all processes
are children of init). If your processes are related you can use this
approach. If not, you can pass the file descriptor through a UNIX
domain socket that you create in the app's private data area.
Another option is to create a file in your app's private data area, or
on /sdcard, and just let everybody mmap() that. Much easier to code,
and you can control access to it via filesystem access permissions on /
data, but it does mean you'll be using up some amount of flash storage
(and add a little system overhead whenever dirty pages are flushed to
disk).