If you ever do use a r/w file, be aware that when you change modes (between write and read), an intervening seek is required to cause the buffers to be flushed to disk. You will see "seek 0 bytes from current position" in the code, that is a no-op functionally but causes a buffer flush.

A weird kind of file that you probably won't see is called a "sparse file". But this weird thing sometimes has its uses. I have made these both on Unix and on Windows. A seek doesn't necessarily leave physical blank space. If you start at the beginning if a file, write a few bytes, seek 1 GB, write a few bytes, seek 1 GB more, write a few bytes, the file on the disk will typically take about 16 KBytes (2 allocation units), not 2 GB. However, if you try to "cat" that file, it will be 2 GB long because the zeroes will be added. One of the big problems with a file like this is how to back it up! That is because a normal copy will "fill in the holes". Anyway, there are applications for a Huge address space that is only sparsely populated.


In reply to Re: What is the point of a+ and w+ when opening files? by Marshall
in thread What is the point of a+ and w+ when opening files? by Maelstrom

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.