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. Dynamic or stack

Dynamic or stack

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 231 Views
  • 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.
  • L Offline
    L Offline
    Lisun
    wrote on last edited by
    #1

    Could anyone explane how classes works in Qt.
    Or maybe its a deeper question - related to how C++ work))
    1.For example i have big txt file (e.g. a.txt) . In my function (e.g foo) i create QFile to work with a.txt.
    if i create it in static way ( QFile a("a.txt")) is it mean all data in a.txt may be putted to stack sometime. I mean , does QFile bufferring data it works with (maybe in some of its functions) or QFile is just functions which operate with memory already reserved by file.
    2. When function returns value (for example QStringList QDir::entryList) where it store this value before returning. I see QStringList returns by value (not a pointer), but if list is a huge list...will it be sent throught stack?
    Will it be better organaize code of function (when big size of data in list is expected) in sach way:
    QStringList* foo(){
    QDir *direct = new QDir(dir);
    QStringList fl =new QStringList(direct->entryList());
    return fl;
    }
    then :
    QStringList foo(){
    QDir direct(dir);
    return direct->entryList());;
    }
    or better:
    QStringList
    foo(){
    QDir direct(dir);
    QStringList *fl =new QStringList(direct->entryList());
    return fl
    }
    Where to read about how it works?

    jsulmJ 1 Reply Last reply
    0
    • L Lisun

      Could anyone explane how classes works in Qt.
      Or maybe its a deeper question - related to how C++ work))
      1.For example i have big txt file (e.g. a.txt) . In my function (e.g foo) i create QFile to work with a.txt.
      if i create it in static way ( QFile a("a.txt")) is it mean all data in a.txt may be putted to stack sometime. I mean , does QFile bufferring data it works with (maybe in some of its functions) or QFile is just functions which operate with memory already reserved by file.
      2. When function returns value (for example QStringList QDir::entryList) where it store this value before returning. I see QStringList returns by value (not a pointer), but if list is a huge list...will it be sent throught stack?
      Will it be better organaize code of function (when big size of data in list is expected) in sach way:
      QStringList* foo(){
      QDir *direct = new QDir(dir);
      QStringList fl =new QStringList(direct->entryList());
      return fl;
      }
      then :
      QStringList foo(){
      QDir direct(dir);
      return direct->entryList());;
      }
      or better:
      QStringList
      foo(){
      QDir direct(dir);
      QStringList *fl =new QStringList(direct->entryList());
      return fl
      }
      Where to read about how it works?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Lisun said in Dynamic or stack:

      QFile a("a.txt")) is it mean all data in a.txt may be putted to stack sometime

      No, QFile does not buffer the whole file.

      "but if list is a huge list...will it be sent through stack?" - Qt containers use implicit sharing (see https://doc.qt.io/qt-5/implicit-sharing.html), so no it will not copy a huge list as long as you do not modify it.

      "Where to read about how it works?" - in a C++ book.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      5

      • Login

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