How to choose a fixed address for shared memory mapping

后端 未结 4 1274
终归单人心
终归单人心 2021-02-13 16:16

I would like to use shared memory between several processes, and would like to be able to keep using raw pointers (and stl containers).

For this purpose, I am using sh

4条回答
  •  情歌与酒
    2021-02-13 17:08

    My solution:

    The initialising program allows the system to select an appropriate segment address. This address is written to disc and retrieved for use by subsequent programs as required.

    Caveats: I am using 64 bit fedora 21 with Kdevelop 4.7 and find that 'void*' is 64 bits long. Writing to disc of the segment head address involves sprintf(bu, "%p", pointer); and writing a text file:

    Recovery reads this file and decodes the hex number as a 'long long' value. This is returned to the caller where it is cast as (void*)

    I have also found that grouping all the access routines into a single folder above the level of the individual processes (each as a project in its own right) has helped save my sanity at the expense of a single aberrant '#include' in the process files

    David N Laine

提交回复
热议问题