[Qt-interest] Will QSettings be cached?
Paul England
pengland at cmt-asia.com
Tue Dec 15 10:34:19 CET 2009
In my experience passing around a pointer to a QSettings object is
somewhat annoying, and the larger the QSettings file get the harder it
is to read. Even in a single threaded environment, I've found it easier
for each of my objects to have it's own QSettings. Easy to debug and is
decoupled from anything else that might not join it in another project.
>> cached
I only use Qt in Linux, and ever time you call QSettings:setValue(),
it's written to disk. Never tested to see if I changed a value from
elsewhere, or even deleted the settings file altogether.
Oliver.Knoll at comit.ch wrote:
> donglongchao wrote on Tuesday, December 15, 2009 8:58 AM:
>
>
>> ...
>> If yes,I think I can create a QSettings object as a global variable
>> and use it directly and quickly(because they are in the memory,not
>> hard disk) anywhere in my app if I want to get/set some value
>>
>
> Why do you worry about the performance of a simple class such as QSettings? Usually you do store small amounts of data, such as a few strings, ints and booleans. Or what is your intention with QSettings?
>
> Even if QSettings would access the disk each time you requested an integer that would not be so bad, because modern file systems have a cache of their own.
>
>
>> ,even in
>> different threads.Is it the right way?Do I need to use QMutex to
>> protect it?
>>
>
> "Use the docs, Luke, use the docs!":
>
> http://qt.nokia.com/doc/4.6/qsettings.html#accessing-settings-from-multiple-threads-or-processes-simultaneously -
>
>
>> AFAIK,the similar thing(I forgot the exact name of it)
>> used to save/read configure informations in GTK+ will be cached. If
>> not,do I have to write/read them from hard disk every time I want to
>> use it?Is there a better and faster way?
>>
>
> Again, do you have concrete performance issues with that? How often do you need to read them? How much data are we talking about? Is there a network involved maybe (latency!)?
>
> Off course you could always look into the Qt source code yourself, but I strongly assume that this is platform-dependent and is not to be exposed to the user. On Windows settings are stored in the registry (or *.ini files), whereas on other platforms *.ini files are used etc. - depending on the implementation settings could be read each time or indeed cached by QSettings (I am totally shooting into the blue here though) - but don't rely on that!
>
> Cheers, Oliver
>
More information about the Qt-interest-old
mailing list