Results 1 to 5 of 5

Thread: saving a c string of variable length in a shared memory?

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

    Default saving a c string of variable length in a shared memory?

    hi there,
    happy new year to everyone!

    i'm looking into ways to save a string of variable length in a shared memory segment.
    the string will be accessed by 2 applications and should be ASCII extended format.
    the one application is a GUI written with QT,in which i write the string length in an int and then a 'char CStringOnShMem' variable follows. in order to write the c string in the memory i memcpy the char* c string to its length , on to a reference &CStringOnShMem in the shared memory. im not so sure this is a nice way but it worked.

    on the other applications side (and remembering that the 2 applications have identical shared memory structures) if i try to memcpy the c string in the same way i only get the first 4 bytes of the string copied. if i try to do a realloc() of the &CStringOnShMem i get a segfault at runtime, which is normal considering the compiler knows that &ToChar is 4bytes long and no realloc should change that.

    so i went back to the GUI and tried to convert the CStringOnShMem to a char* and do a realloc just b4 the memcpy. but i get a segfault at runtime on the GUI side now too. any suggestions?
    thank youi in advance for your help
    nass

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

    Default Re: saving a c string of variable length in a shared memory?

    Can we see the code?

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

    Default Re: saving a c string of variable length in a shared memory?

    hm in the end i just managed to solve it.
    a memcpy is done later on that did not take into account the string length and so never copied its data.
    thank you very much for your help
    nass

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

    Default Re: saving a c string of variable length in a shared memory?

    Eeeem.... you're welcome

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

    Default Re: saving a c string of variable length in a shared memory?

    still don't vanish into thin air! im coming up with another question about strings and locales in unix. same subforum different topic

Similar Threads

  1. How to get size (length, width ....) of string or char
    By Krishnacins in forum Qt Programming
    Replies: 1
    Last Post: 20th March 2006, 09:55

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.