Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Serialization vs Binary File

Serialization vs Binary File

Scheduled Pinned Locked Moved C#
questionvisual-studiowindows-adminxmljson
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mark F
    wrote on last edited by
    #1

    I made a simple configuration class to store program settings. My reason for this was to make the form application more portable (no HDD installation required), able to run on removable drives (e.g., USB), and did not write information to the user's profile or the registry. The answer was obviously a binary data file. My first test was serialize/deserialize my properties using BinaryFormatter in a serializable class. Although I could have used XML serialization, I chose the binary file route versus text. The test second option was to simply read and write the properties using BinaryReader and BinaryWriter. The resulting output file (I call settings.bin) is about 1,000 bytes larger with the serialization technique then with the BinaryWriter option. My question is; are there any performance differences between the two? Thanks, Mark

    J 1 Reply Last reply
    0
    • M Mark F

      I made a simple configuration class to store program settings. My reason for this was to make the form application more portable (no HDD installation required), able to run on removable drives (e.g., USB), and did not write information to the user's profile or the registry. The answer was obviously a binary data file. My first test was serialize/deserialize my properties using BinaryFormatter in a serializable class. Although I could have used XML serialization, I chose the binary file route versus text. The test second option was to simply read and write the properties using BinaryReader and BinaryWriter. The resulting output file (I call settings.bin) is about 1,000 bytes larger with the serialization technique then with the BinaryWriter option. My question is; are there any performance differences between the two? Thanks, Mark

      J Offline
      J Offline
      Jelle Hissink
      wrote on last edited by
      #2

      Mark, BinaryReader/Writer should be much faster, however as you are using it only on a small settings file that will propably only be read at startup and saved only when the user changes something. The BinaryFormatter should be fine. However writing your own file format is somewhat additional work, it simplify upgrades of your software. The formatter might fail when you add, change or remove fields in your settings. Why can't you use System.Configuration do the work for you, it was made to handle settings (stored in .config files so you can put them on your USB stick). Regards, Jelle Hissink

      http://www.CodeWise.nl

      M 1 Reply Last reply
      0
      • J Jelle Hissink

        Mark, BinaryReader/Writer should be much faster, however as you are using it only on a small settings file that will propably only be read at startup and saved only when the user changes something. The BinaryFormatter should be fine. However writing your own file format is somewhat additional work, it simplify upgrades of your software. The formatter might fail when you add, change or remove fields in your settings. Why can't you use System.Configuration do the work for you, it was made to handle settings (stored in .config files so you can put them on your USB stick). Regards, Jelle Hissink

        http://www.CodeWise.nl

        M Offline
        M Offline
        Mark F
        wrote on last edited by
        #3

        Jelle Hissink wrote:

        Why can't you use System.Configuration do the work for you, it was made to handle settings (stored in .config files so you can put them on your USB stick).

        Because the settings files are written to the user's "%UserName%\Application Data\Program_Name\" folder, and these are also XML (text) files. The binary disk file, is in the same folder as the application and is always available. So, if I move the application to another PC my settings are there too. This obviously wouldn't work with registered DLL's and other support files that would require a hard disk install. Mark

        J 1 Reply Last reply
        0
        • M Mark F

          Jelle Hissink wrote:

          Why can't you use System.Configuration do the work for you, it was made to handle settings (stored in .config files so you can put them on your USB stick).

          Because the settings files are written to the user's "%UserName%\Application Data\Program_Name\" folder, and these are also XML (text) files. The binary disk file, is in the same folder as the application and is always available. So, if I move the application to another PC my settings are there too. This obviously wouldn't work with registered DLL's and other support files that would require a hard disk install. Mark

          J Offline
          J Offline
          Jelle Hissink
          wrote on last edited by
          #4

          You can extend the SettingsManager in .Net (search for the SettingsProvider class). It allows you to implement your own read/save mechanism for settings. Some links: Google Some random results from google: VB.Net example saving all settings in seperate files C# example writing to .ini file a forum thread trying to implement a SettingsProvider Jelle

          http://www.CodeWise.nl

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups