Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. file mapping between process
Forum Updated to NodeBB v4.3 + New Features

file mapping between process

Scheduled Pinned Locked Moved Unsolved General and Desktop
file mapping
4 Posts 2 Posters 1.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ivanperinoI Offline
    ivanperinoI Offline
    ivanperino
    wrote on last edited by
    #1

    My process "A" use QFile.map(...) to map a portion of NVRAM device (it is at /dev/sram0) to a struct of data inside process A. So I don't need to care about saving variables to NVRAM, it happens transparent for me. It works ok.

    MyNvStruct * nvInfo:
    QFile nvfile;
    nvfile.setFileName("/dev/sram0");
    nvfile.open(QIODevice::ReadWrite);
    nvInfo = reinterpret_cast<MyNvStruct *>(nvfile.map(0,sizeof(MyNvStruct)));
    

    Now I need to use another portion of such a NVRAM device inside another process, process B. I dont need to share anything between process A and B , just to use the rest of NVRAM resourse inside another process.

    Is it possible to reopen /dev/sram0 with ReadWrite property inside another process?
    I would map NVRAM from sizeof(MyNvStruct) on.
    Both process run simultaneously and should access NVRAM resourse separately.

    Thanks in advance

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      /dev/sram0 will not be deleted by map so you can pass it to another process, an alternative would be to use a QLocalSocket to make the 2 processes talk to each other.

      P.S.
      This:
      nvInfo = reinterpret_cast<MyNvStruct *>(nvfile.map(0,sizeof(MyNvStruct)));
      Has the potential to create endless headaches if you ever assign memory on the heap inside MyNvStruct or the binary version you use in process A is different from the one in process B

      if you are interested in a pre-built memory map take a look here: http://pastebin.com/SBZBeKWN

      It uses QDataStream::operator>> and QDataStream::operator<< of the class to read from and write to the mapped device, you need to implement:

      QDataStream&  operator<<(QDataStream & stream, const MyNvStruct& flows);
      QDataStream& operator>>(QDataStream & stream, MyNvStruct& flows);
      

      and then you can use the device more or less how you use QMap

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      2
      • ivanperinoI Offline
        ivanperinoI Offline
        ivanperino
        wrote on last edited by
        #3

        VRonin, thank you for your quick response.
        I dont need to share memory between these 2 process, neither talk to each other. I just need to use /sram0 device (from advantech platforms) from 2 different process. taking care of course of not mapping the same portion of NVRAM in both process.

        Regarding headaches, I understand your advice. MyNvStruct is a very basic struct with just a couple of int and unsigned long, It does not grow dynamically. I am aware of this.

        So, It is posible open sram0 file from different process and thus share this NVRAM resourse, I have just tested. My question is now if this is a solid and well seen way to use NVRAM from different processess.
        Thank you very much

        1 Reply Last reply
        0
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

          As long as you access it just for reading it should be safe

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved