Lately I've been using PDF::API2 within a CGI script that handles the uploading and processing of PDF files. Because my program ran so slowly on the antiquated box I have at work, I started to run the script with Devel::Profiler on. After a single run, I found that the vast majority of the program's running time was spent making call after call to IO::Handle's read.

After looking at the source for PDF::API2, I found that each read call was pulling in only 512 characters at a time. I made an alternative version that pulled in 65536 characters instead and found that my program ran more than four times as fast.

With that observation in mind, I wrote to the module's author, suggesting that the LENGTH used by read calls be an option that could be set by the user of the module. He responded by noting that 512 bytes is the POSIX limit on file blocks and that, therefore, a larger size cannot be guaranteed to work on all systems.

I'm interested in knowing how many types of systems this could be a problem on, because almost all of the Perl programs I've seen written these days contain read calls fetching more than 512 characters at a time. My understanding is that the Perl read calls are translated into as many stdio fread(3) calls as necessary. Is this not true? And is my program going to mysteriously fail on a modern platform if I take the risk of using the larger length?

Thanks for whatever details anyone has to offer about read lengths.

-- John


In reply to Portability of Large read Lengths by johnmyleswhite

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.