File storage

This is a discussion on File storage within the Windows Programming forums, part of the Platform Specific Boards category; I have some questions about file storage in Windows programming. First, when you write to a file, it is not ...

  1. #1
    lyx
    lyx is offline
    Amateur
    Join Date
    Sep 2003
    Posts
    228

    File storage

    I have some questions about file storage in Windows programming.
    First, when you write to a file, it is not written to the disc directly, is it?
    But when you want it to be written to the disc and flush the buffers, how do I do that?
    And, if then I close the handle, it is saved to the disc, however, if it happened to crash, will it be saved anyway?

    Thanks.

  2. #2
    Registered User lobo's Avatar
    Join Date
    Oct 2001
    Posts
    71
    >First, when you write to a file, it is not written to the disc directly

    ..it depends on flags specified when opening file (via CreateFile()), you can specify flags there to ignore buffering, default is to use it.

    >when you want it to be written to the disc and flush the buffers

    If you did not turned write buffering off, you can call FlushFileBuffers() to flush buffers for given file.

    >if then I close the handle, it is saved to the disc, however, if it happened to crash

    If crash happens after succesfull CloseHandle(), data should be written already and OK - closing a handle includes flushing of all relevant buffers as well. Otherwise it depends on settings of buffers and your own requests for flushing, how much of the file will be saved.

  3. #3
    lyx
    lyx is offline
    Amateur
    Join Date
    Sep 2003
    Posts
    228
    Thanks for answering.

  4. #4
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    Remember, there is also the cache on the disc drive itself, always possible to flush the OS cache to the UDMA controller, but that writes to the cache on the drive, because the cache is so much faster than the physical device. Technically possible that after flushing everything you can possible flush, a badly times power drop could prevent the magnetic media from being completely updated.

    lobo:

    It says 23 posts and newbie basically, but you were around before weren't you?
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  5. #5
    Registered User lobo's Avatar
    Join Date
    Oct 2001
    Posts
    71
    adrianxw: of course .. i haven't been checking this board for quite a time due to bad internet access but times changed and i'm back.. quite a surprise to me you do remember

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 10:39 PM
  2. Replies: 3
    Last Post: 03-04-2005, 01:46 PM
  3. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM
  4. Hmm....help me take a look at this: File Encryptor
    By heljy in forum C Programming
    Replies: 3
    Last Post: 03-23-2002, 09:57 AM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 01:58 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21