Interesting question for preferences saving/restoring

  • Thread starter Thread starter Tom
  • Start date Start date
T

Tom

I have a large application; lots of forms, multiple dynamic DLLs, etc. I
also have, in the appliation, a general 'Preferences' class object (which is
in itself a separate DLL, and I just include a reference to it so I can
instantiate it at the beginning) which stores all my user preferences. I
serialize the data to and from an XML file, thereby saving and restoring the
user preferences with ease. I also have a Preferences form that the user can
select to modify certain preferences themselves, such as colors, etc. (I say
'certain' because I also save non-browsable preference such as window
location, window size, etc)

I have basically two options to work with the preferences class in my
application: (a) When I load the application, instantiate the preferences
class, load it from the XML file, then keep that class in memory,
referencing the properties as needed. I would also need to 'pass' a
reference to this class around since I do load and use dynamic DLLs. Or (b)
Everytime I need to reference or save a preference, I would simply reload
the class from the XML file, make my modification (or read the data), then,
if needed, re-save the file back out to XML.

The advantages of option A is that, in theory, I only have to read the file
once and then write it out once (I say 'in theory' becuase, when the user
loads the preferences panel, I should save anything that had been modified
up to this point, then re-save the preferences once the user closes the
preferences panel so that things are saved properly). However, it can be a
pain passing the references around to everything, especially since I use
dynamically loaded DLLs. Option B has the advantage in that whenever I
deserialize the preferences class I -KNOW- that I have the latest and
greatest preferences settings. The disadvantage is that I have to read and
write (serialize and deserialize) it every time I want to access or store
information into the class object; and I don't know what kind of performance
hit it will take doing this all the time.

Now the question is: What do you think would be the best method of doing
this? A or B? Or is there another way? I've tried to do a combination of the
two, but it is ending up being very complicated trying to keep things in
sync. I can go either way but was just wondering what everyone thought might
be a better (and more OOP) method of doing it.

Thanks in advance.

Tom
 
Option A is probably the way I would go. However another downside to that is
the more you store in memory the more likely your application will run out
of memory. But when a user loads a form it should be quick and if you have
to read the file to determine color of objects and display names, etc. it
will increase the form's loading time. It might not be a big deal but if you
also have to load data every millisecond counts.

Brad Shook
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top