Results 1 to 2 of 2

Thread: Question about the example "\Qt\4.6.2\examples\ipc\sharedmemory"

  1. #1
    Join Date
    Apr 2008
    Posts
    44
    Thanks
    21
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Question about the example "\Qt\4.6.2\examples\ipc\sharedmemory"

    I have some question to the following code:
    Qt Code:
    1. int size = buffer.size();
    2.  
    3. if (!sharedMemory.create(size)) {
    4. ui.label->setText(tr("Unable to create shared memory segment."));
    5. return;
    6. }
    7. sharedMemory.lock();
    8. char *to = (char*)sharedMemory.data();
    9. const char *from = buffer.data().data();
    10. memcpy(to, from, qMin(sharedMemory.size(), size));
    11. sharedMemory.unlock();
    To copy to clipboard, switch view to plain text mode 

    1.
    Qt Code:
    1. sharedMemory.create(size)
    To copy to clipboard, switch view to plain text mode 
    Creates a shared memory segment of size bytes,Why sharedMemory.size() != size?
    2.In addition, it seems like not sure about which one is big between sharedMemory.size() and
    Qt Code:
    1. size(qMin(sharedMemory.size(), size)
    To copy to clipboard, switch view to plain text mode 
    ) ?


    thanks very much for any advice!

  2. #2
    Join Date
    Jun 2010
    Posts
    23
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Re: Question about the example "\Qt\4.6.2\examples\ipc\sharedmemory"

    Hey,

    Qt Code:
    1. sharedMemory.create(size)
    To copy to clipboard, switch view to plain text mode 
    creates a sharedMemory with a size rounded up to a multiple of pagesize.

    I think that
    Qt Code:
    1. size(qMin(sharedMemory.size(), size)
    To copy to clipboard, switch view to plain text mode 
    is important to check, because it is possible that another Thread has changed the sharedmemory before it was locked.
    Last edited by CeeKey; 2nd June 2010 at 09:35.

Similar Threads

  1. Replies: 1
    Last Post: 7th April 2010, 21:46
  2. Replies: 3
    Last Post: 15th February 2010, 17:27
  3. Replies: 3
    Last Post: 8th July 2008, 19:37
  4. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 19:05
  5. QFile Problem~ "Unknow error" in "open(QIODevice::ReadWrite)"
    By fengtian.we in forum Qt Programming
    Replies: 3
    Last Post: 23rd May 2007, 15:58

Tags for this Thread

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.