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 / C++ / MFC
  4. Client Server Application - Design issue - Writing to a file sequentialy during a session

Client Server Application - Design issue - Writing to a file sequentialy during a session

Scheduled Pinned Locked Moved C / C++ / MFC
designsysadminhelpquestion
5 Posts 5 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.
  • S Offline
    S Offline
    simon alec smith
    wrote on last edited by
    #1

    The client server application, is a simple purchase order application I wish to write each order received by the server sequentially to a file. What would be best practise? (1) Keep the file open whilst the program is running, then write each order received during the server session, then close the file when the program ends. (2) Open then write the record then close the file for each order received What would be the pros and cons for the above mentioned? Thanks in advance Simon

    M _ T A 4 Replies Last reply
    0
    • S simon alec smith

      The client server application, is a simple purchase order application I wish to write each order received by the server sequentially to a file. What would be best practise? (1) Keep the file open whilst the program is running, then write each order received during the server session, then close the file when the program ends. (2) Open then write the record then close the file for each order received What would be the pros and cons for the above mentioned? Thanks in advance Simon

      M Offline
      M Offline
      Moak
      wrote on last edited by
      #2

      Which one is more attractive? Well, number 2 is more flexible in case someone else has to edit/archive orders... unless you are running into performance problems, which would make number 1 the more attractive contender in this battle of designs.

      Chat in Europe :java: Now with 24% more Twitter

      1 Reply Last reply
      0
      • S simon alec smith

        The client server application, is a simple purchase order application I wish to write each order received by the server sequentially to a file. What would be best practise? (1) Keep the file open whilst the program is running, then write each order received during the server session, then close the file when the program ends. (2) Open then write the record then close the file for each order received What would be the pros and cons for the above mentioned? Thanks in advance Simon

        _ Offline
        _ Offline
        _Superman_
        wrote on last edited by
        #3

        No. 1 is better in terms of performance. You could give it read share access if any other program wishes to read the same file when it is kept open.

        «_Superman_»
        I love work. It gives me something to do between weekends.

        Microsoft MVP (Visual C++)

        Polymorphism in C

        1 Reply Last reply
        0
        • S simon alec smith

          The client server application, is a simple purchase order application I wish to write each order received by the server sequentially to a file. What would be best practise? (1) Keep the file open whilst the program is running, then write each order received during the server session, then close the file when the program ends. (2) Open then write the record then close the file for each order received What would be the pros and cons for the above mentioned? Thanks in advance Simon

          T Offline
          T Offline
          ThatsAlok
          wrote on last edited by
          #4

          simon alec smith wrote:

          (2) Open then write the record then close the file for each order received

          I always prefer (2) one, because if there is any crash, chances of data-loss is very much. Secondly it also depend how frequently is data coming, if it quite fast, then option 1 also stands good.

          "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
          Never mind - my own stupidity is the source of every "problem" - Mixture

          cheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You

          1 Reply Last reply
          0
          • S simon alec smith

            The client server application, is a simple purchase order application I wish to write each order received by the server sequentially to a file. What would be best practise? (1) Keep the file open whilst the program is running, then write each order received during the server session, then close the file when the program ends. (2) Open then write the record then close the file for each order received What would be the pros and cons for the above mentioned? Thanks in advance Simon

            A Offline
            A Offline
            Aescleal
            wrote on last edited by
            #5

            As the others have mentioned keeping the file open will be faster but second will be more secure if something goes wrong. You might be able to get some of the the performance of keeping the file open with opening and closing it every time by opening the file unbuffered. This[^] has got loads of useful info about the pain in the neck this is to sector align buffers if you're on windows. You can do something similar on Linux with the open() system call. It all depends on how much money's involved if something goes wrong and how much the customer is willing to pay for security. Another solution might be to open and close the file every transaction and make sure the powers that be spend the money they'd have spent on you engineering a software solution on more memory for the server to reduce the impact of repeated opens and closes. Another option might be to try the double open trick that used to work years ago on some Unixen and DOS. You'll have to see if this does any good, I've not used it on any version of windows since Windows '95. What you do is open the file when the program starts. This makes a second opening really quick when you write a transaction. when you finish writing the transaction you close the file which flushes it to disk. Finally when the program terminates you close the original opening. Cheers, Ash

            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