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. Data Block Copy Question
Forum Updated to NodeBB v4.3 + New Features

Data Block Copy Question

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 4 Posters 1.6k Views 3 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.
  • C Offline
    C Offline
    Crag_Hack
    wrote on last edited by
    #1

    I have a quick question. I have a data backup program that reads source files in QByteArray blocks of at most 1,000,000 bytes in size. Might I be able to irk out more performance by using a smaller or larger block size? Does it depend on the source and target media and/or the file size?
    Thanks!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You should do benchmarks.

      Speed depends on:

      • device type (Hard Drive, SSD, Flash, NAND, MMC, etc.)
      • bus type (USB, FireWire, ATA, SATA, etc.)
      • storage technology (RAID0-5, JBOD, etc.)
      • File system type (ext2,3,4, ReiserFS, ZFS, exFAT, APFS, HFS+, etc)
      • System load
      • Network load if using a NAS

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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

        if you are taking a copy of a file from one place to the other, using QFile::copy instead might turn out to be faster

        "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
        • C Offline
          C Offline
          Crag_Hack
          wrote on last edited by
          #4

          Thanks SGaist. Any numbers you suggest starting with? Will large amounts of small files have different properties than larger files?

          1 Reply Last reply
          0
          • C Offline
            C Offline
            Crag_Hack
            wrote on last edited by
            #5

            Thanks VRonin. I need to track progress so have to use block by block.

            VRoninV 1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Yes they will but it will also depend on your file system. Having lots of small files means that you will have more IOCTL calls to open and close the files so more "times lost" there.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              1
              • C Crag_Hack

                Thanks VRonin. I need to track progress so have to use block by block.

                VRoninV Offline
                VRoninV Offline
                VRonin
                wrote on last edited by VRonin
                #7

                @Crag_Hack said in Data Block Copy Question:

                I need to track progress so have to use block by block.

                UNTESTED

                #include <QCoreApplication>
                #include <QTimer>
                #include <QFile>
                #include <QFileInfo>
                #include <QFuture>
                #include <QDebug>
                #include <QFutureWatcher>
                #include <QtConcurrent>
                int main(int argc, char *argv[])
                {
                    QCoreApplication a(argc,argv);
                    QTimer progressTimer;
                    const QString source("mySourceFile.dat");
                    const QString destination("myDestFile.dat");
                    const qint64 sourceSize = QFileInfo(source).size();
                    QEventLoop pauser;
                    QFutureWatcher<void> signaler;
                    QObject::connect(&signaler,&QFutureWatcher<void>::finished,&pauser,&QEventLoop::quit);
                    QFileInfo destInfo(destination);
                    QObject::connect(&progressTimer,&QTimer::timeout,[&destInfo,&sourceSize]()->void{
                        destInfo.refresh();
                        qDebug() << "Progress: " << static_cast<qint64>(100)*destInfo.size()/sourceSize << "%";
                    });
                    const QFuture<void> future = QtConcurrent::run(std::bind(&QFile::copy,source,destination));
                    signaler.setFuture(future);
                    progressTimer.start(50);
                    pauser.exec();
                    progressTimer.stop();
                    return 0;
                }
                

                "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

                kshegunovK 1 Reply Last reply
                4
                • VRoninV VRonin

                  @Crag_Hack said in Data Block Copy Question:

                  I need to track progress so have to use block by block.

                  UNTESTED

                  #include <QCoreApplication>
                  #include <QTimer>
                  #include <QFile>
                  #include <QFileInfo>
                  #include <QFuture>
                  #include <QDebug>
                  #include <QFutureWatcher>
                  #include <QtConcurrent>
                  int main(int argc, char *argv[])
                  {
                      QCoreApplication a(argc,argv);
                      QTimer progressTimer;
                      const QString source("mySourceFile.dat");
                      const QString destination("myDestFile.dat");
                      const qint64 sourceSize = QFileInfo(source).size();
                      QEventLoop pauser;
                      QFutureWatcher<void> signaler;
                      QObject::connect(&signaler,&QFutureWatcher<void>::finished,&pauser,&QEventLoop::quit);
                      QFileInfo destInfo(destination);
                      QObject::connect(&progressTimer,&QTimer::timeout,[&destInfo,&sourceSize]()->void{
                          destInfo.refresh();
                          qDebug() << "Progress: " << static_cast<qint64>(100)*destInfo.size()/sourceSize << "%";
                      });
                      const QFuture<void> future = QtConcurrent::run(std::bind(&QFile::copy,source,destination));
                      signaler.setFuture(future);
                      progressTimer.start(50);
                      pauser.exec();
                      progressTimer.stop();
                      return 0;
                  }
                  
                  kshegunovK Offline
                  kshegunovK Offline
                  kshegunov
                  Moderators
                  wrote on last edited by
                  #8

                  Interesting approach. One could probably also monitor the file changes through QFileSystemWatcher instead of a timer.

                  Read and abide by the Qt Code of Conduct

                  1 Reply Last reply
                  3
                  • C Offline
                    C Offline
                    Crag_Hack
                    wrote on last edited by
                    #9

                    Wow VRonin you got creative :)

                    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