Memory difference between QMap<MyInst,QColor> and QMap<MyInst,QString)
-
so QString takes more memory that QColor ?
-
so QString takes more memory that QColor ?
@Qt-Enthusiast
yes. on 64 bit, even more. -
so QString takes more memory that QColor ?
@Qt-Enthusiast
18 bytes for aQColor
instance vs about 30 bytes for aQString
object with 6 letters (QString
will also keep one zero character at the end and will store the length, as addition to the things I've described in my edit). So yes,QColor
will take less memory.But I just can't stress this enough: use what makes sense. Even if
QString
were more memory efficient, the complications and the needed CPU time for conversions between colors and strings just makes it unsuitable. And small wonder, it's supposed to be a general purpose string, not a color. There's a separate class that represents colors, so you should use that in any case and not worry about how much bytes anything takes unless you hit the memory limit (which seems doubtful at this point). -
@Qt-Enthusiast
18 bytes for aQColor
instance vs about 30 bytes for aQString
object with 6 letters (QString
will also keep one zero character at the end and will store the length, as addition to the things I've described in my edit). So yes,QColor
will take less memory.But I just can't stress this enough: use what makes sense. Even if
QString
were more memory efficient, the complications and the needed CPU time for conversions between colors and strings just makes it unsuitable. And small wonder, it's supposed to be a general purpose string, not a color. There's a separate class that represents colors, so you should use that in any case and not worry about how much bytes anything takes unless you hit the memory limit (which seems doubtful at this point).@kshegunov Yes, using QString instead of QColor to represent a colour just to save some bytes is an example for how not to optimize software.
@qtEnthusiast why not use an 32bit unsigned int to represent a colour? This way you only need 4 bytes. -
@kshegunov Yes, using QString instead of QColor to represent a colour just to save some bytes is an example for how not to optimize software.
@qtEnthusiast why not use an 32bit unsigned int to represent a colour? This way you only need 4 bytes. -
@jsulm
Following your thought of unsigned intWould
QMap<MyInst,QRgb);be as good?
It does seems
QColor::QColor(QRgb color)will ignore alpha.
-
@kshegunov Yes, using QString instead of QColor to represent a colour just to save some bytes is an example for how not to optimize software.
@qtEnthusiast why not use an 32bit unsigned int to represent a colour? This way you only need 4 bytes.Can u tell me how to represent integer for colors because we can have millions of colors ?
-
Can u tell me how to represent integer for colors because we can have millions of colors ?
@Qt-Enthusiast 32bit integer can represent billions of values/colors.
RGB - means 1byte for red, 1byte for green and one byte for blue. Since 32bit integer consists of 4 bytes you still have one byte for alpha channel. -
Can u tell me how to represent integer for colors because we can have millions of colors ?
-
What exactly do you want to do with that map ?