PDA

View Full Version : What's least expensive? (memory)



codeslicer
20th February 2010, 00:40
What would be least expensive in this situation?


QStringList lineStringList = file->readLine().split("\t");

or


QString lineString = file->readLine();
QStringList lineStringList = lineString.split("\t");

Thanks!

BTW, the first one doesn't compile because it's not a QString but a byte array, but still, is it better to create a variable for each step or to combine?

~codeslicer

Lykurg
20th February 2010, 11:57
In general it is better to avoid temporary variables. (But sometimes this is not so good for a readable source code...)

Lykurg
20th February 2010, 13:13
As a short note:
BTW, the first one doesn't compile because it's not a QString but a byte array
QStringList lineStringList = QString(file->readLine()).split("\t"); would work.

nish
20th February 2010, 13:53
both version will use same amount of memory. The compiler optimize away temp variables.