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