Most hard disks won't allow you to read less than 512 bytes at a time. Most file systems won't allow you to read less than around 4K or 8K bytes at a time. The operating system (and/or C RTL) hide these facts from you, but that just means that when you ask for 1 byte of a file, 8K of the file is read by the operating system and 1 byte of that 8K is given to you.

So reading a power of two multiple of 4K bytes at a time is usually a good thing... to a point...

Reading 4MB is probably a pretty dumb idea, especially if you just plan to throw all (or even most) of that data away. Allocating a 4MB buffer just isn't a trivial thing on most systems. Then as the buffer is filled, pages of memory have to be allocated to slowly cover the huge chunk of virtual address space you managed to reserve. It is much more efficient, in most cases, to just reuse a few dozen pages of RAM for reading reasonably sized chunks of data that you plan to throw away.

        - tye (but my friends call me "Tye")

In reply to (tye)Re: how to choose read size for read() and sysread() by tye
in thread how to choose read size for read() and sysread() by princepawn

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.