Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Which method is considered to be best practice for setting storage for applications: XML or Registry? What are the benefits/downsides of using either of these?

share|improve this question
2  
"setting storage"? Do you mean "storing an application's settings"? Also, XML is just a language (it can work in a file or in a database) and registry only applies to Windows. It would help if you could clarify the platforms, and why you're comparing a language with an OS feature. –  S.Lott Mar 10 '11 at 17:45
    
XML makes a rather lousy for storing settings and most other lightweight data. –  delnan Mar 10 '11 at 17:51
    
@delnan would I be correct in assuming then that you use the registry for this kind of storage or do you use a different approach? Can you elaborate on why you think XML is lousy for this purpose? Thanks! –  Kenneth Mar 10 '11 at 18:54
4  
It depends. If I was targeting Windows alone, I'd think about using the registry. But generally, I'd use the simplest file format that could possibly do the job (well) - in simpler cases, a plain old .ini file. XML is a heavy, flexible format, powerful enough for tasks like storing a whole database for import/export. But it's overkill for simple key-value pairs and other simple relations. Especially when you'd need to add an XML parser for the config files alone. –  delnan Mar 10 '11 at 19:07

4 Answers 4

up vote 4 down vote accepted

The registry is Microsoft's solution to storing application information relative to a user. The advantages of this include:

  • Being able to hold application settings for each user of the computer.
  • Having an API already available for using this feature.

However the disadvantages include:

  • Platform dependent.
  • Limited to the amount of information for a single block of data.
  • Loss of portability (you lose settings when you install on another machine)

I personally vouche for using XMLs if not merely for the fact that it allows you to copy the entire application to another computer and have it work fine with the same settings. Plus, if you write your application flexible enough, you can write entire projects onto XML files, something I wouldn't dare attempt with a registry.

It's convenient initially to use the registry, but it's far better in the long run to use XML files in my opinion.

share|improve this answer

A major downside of the registry in Windows Vista and forward is that you can only store stuff in HKEY_CURRENT_USER unless you're running elevated.

That means that if your non-elevated program stores stuff in HKCU, and the user installs a new version of the program, the installer likely runs elevated, which may mean running under a different user account.

That means that you can't rely on being able to read program information out of the registry from the installer, because the installer is running under a different user, who has different stuff in their registry. :(

share|improve this answer

For information that may be needed by other programs, such as the location and current version of an executable, store that in the registry.

For information that is only needed by your application, store that in a file in the user's AppData directory. Use XML or whatever you find suitable, depending on the structure of the data.

That allows the registry to do its job - function as a central registry of applications - without cluttering it up.

It'll also make your testing life a little easier, since you can wipe the AppData file and reset the app back to defaults.

share|improve this answer

On Windows, I feel program settings belong in the registry. While xml-files may be easier to copy by hand, backup and restore procedures routinely include the registry, and they also support multiuser setups, where program install directories may not be preserved (nor would I want that, because paths may not be the same, and installers usually also take care of associating files and creating shortcuts. So on Windows, I mostly prefer installers over copying directories. A function (from the gui) to export and import settings may really help migration though.

Project settings are perhaps better stored in the document or project directory. That allows for version control and sharing across users.

share|improve this answer
1  
The whole U3 application (flash drive installation) thing relies on not having things in the registry, so for portable apps even on Windows the registry might not be the best choice. –  DaveE Mar 10 '11 at 21:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.