From: Fred P. <fps...@ya...> - 2007-06-07 03:31:11
|
On 05/25/2007 07:55 AM, Vlad Horsun wrote: >>>> Are you sure other OS's also support such regions? >>> Some time ago someone told about it here, IIRC. >> mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset) >> Name of region is name of file. No problems creating anonymous mapping (in >> that case fd is ignored), but it makes no sense for embedded access. > > Are posix have some special name space for 'files' which is not mapped to > real disk files ? Have a look at the shm_open() and shm_unlink() POSIX functions. Put simply, shm_open() opens/creates a named "Shared Memory Object" and returns a file descriptor for that object. You can call ftruncate() on the resulting fd to size the memory object as needed. You can pass the fd to mmap() to map the object into your address space. Function shm_unlink() unlinks the object's name from system. These functions were added as part of the POSIX Realtime Extension back in the '90s. Like a lot of POSIX functionality (e.g., mmap), these are "optional" on a given implementation. However, these days, many systems support these functions (e.g., GNU/Linux, Sun, HP, BSD, Darwin, etc.). Note: some systems require that another library be linked with apps calling these functions (e.g. "librt" on Sun and GNU/Linux). Try this URL for more details and an example of shm_open() usage: http://www.opengroup.org/onlinepubs/000095399/functions/shm_open.html Hope this helps, Fred P. |