Results 1 to 10 of 10

Thread: how to write a structure in a shared mem segment.

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2006
    Posts
    79
    Qt products
    Qt3 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: how to write a structure in a shared mem segment.

    cool i found the answer as to why this is
    basically a void* can not be dereferenced because it has no type...
    so trying to offest a void* the compiler didn't know the base unit of offset (ie for a char the offseting is 1byte, for int its 4bytes, for double 64bytes).. so basically i cast the void* to char* in order to do the offset (since i know the offset i need in single byte units), then recast it to myStruct*...
    lets see it its gonna save though..

  2. #2
    Join Date
    Jul 2006
    Posts
    79
    Qt products
    Qt3 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: how to write a structure in a shared mem segment.

    ok i have created a shared memory segment and can save data into it.. i can check because the segment is directly connected to a file in the disk. so yes i have verified data (bytes really) is written into the memory. the problem is reading...
    basically just like in saving i create the same exact structure:
    struct manualStruct {
    Q_UINT8 mC1St;
    Q_UINT8 mC2St;
    Q_UINT8 mC3St;
    };
    and then
    struct manualStruct *manualVar=(manualStruct*)((char*)file_memory + 0xC5);
    basically file_memory is a void* pointer to the shared memory segment, so i cast it, add an offset to the exact location where data is written and then i simply assingn manualVar.
    next i should be able to just:
    MANUAL_cap1State=manualVar->mC1St;
    MANUAL_cap2State=manualVar->mC2St;
    MANUAL_cap3State=manualVar->mC3St;
    where MANUAL_* variables are int.
    then i just test with cout to see if the values have been copies and well they haven't...
    any ideas why?
    nass

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: how to write a structure in a shared mem segment.

    Did you check that the shared segment got updated? For example by printf()ing the data directly from within the shared segment.

  4. #4
    Join Date
    Jul 2006
    Posts
    79
    Qt products
    Qt3 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: how to write a structure in a shared mem segment.

    isnt it sufficient looking directly at the associated file on the disk?
    cause as soon as i save, i can see changes on the file... so i figure i save in the shared memory and directly the file on the disk is updated. causei surely dont write to the file.. i just 'save' to a location pointed to by the file_memory pointer (+ the offset)
    nass

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: how to write a structure in a shared mem segment.

    Quote Originally Posted by nass View Post
    isnt it sufficient looking directly at the associated file on the disk?
    If it seems that the segment is not updated, then it's better to check that out. There is no reason why the assignment should fail, so if it fails, there is a reason to suspect that the segment wasn't updated.

Similar Threads

  1. Qt 4.1.1 linker warnings
    By Matt Smith in forum Installation and Deployment
    Replies: 0
    Last Post: 26th February 2006, 22:14

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.