Re: Serialized r/w access to a collection from multiple processes - DLL or EXE?



<mr.intj@xxxxxxxxx> wrote:
I'm looking for some help on a design issue. We have a scenario where
one or more instances of our app EXEs will be accessing the same
collection of items. This collection is lazily persisted to disk after
any modification.

I could package this in a DLL, and use a shared data segment or memory-
mapped file to share the data across all mappings of the DLL, but if
the host EXE were to crash during a lazy serialization (timer
thread)... I don't see how to avoid leaving a half-written file.


You could adopt MS Office approach:

1. Flush memory content into new temporary file.
2. If write succeeds, then rename original file.
3. Rename new temporary file to original name.
4. Delete old original file.

This way you have valid copy of a file at any given moment. Probably you can store temporary names somewhere before write operation, so in case of crash you will be able to recover files on first launch.

HTH
Alex

.



Relevant Pages

  • RE: Locked for editing???
    ... removable disk, such as a floppy diskette, the disk has been removed. ... file name and places this file in the same folder as the original file. ... The process was interrupted while creating the temporary file because you ... If the interruption was caused ...
    (microsoft.public.excel.setup)
  • Re: Newbie howto question.
    ... I can identify the tagged information, ... >said info and write it to the html file, ... create a new temporary file for writing ... read the first line from original file. ...
    (comp.programming)
  • RE: How is the ~$... file created when you open a document used?
    ... This temporary file holds the logon name of the person ... If the Owner File is damaged or missing the error message changes to: ... Word automatically deletes the Owner File when the original file is closed. ... I understand that Word opens a "copy" of the file and you ...
    (microsoft.public.word.docmanagement)
  • Re: c++ fstream writing to existing file
    ... rewind the original file. ... copy the contents from the temporary file back to the original. ... The universe is a figment of its own imagination. ...
    (comp.lang.cpp)

Quantcast