AFAIK, stdio buffering - as configurable via setvbuf - is incompatible with PerlIO's buffering, which is why it's disabled when you configure Perl to use PerlIO.  OTOH, you most probably do want PerlIO... so configuring/rebuilding Perl to not use it, isn't really an option.

Anyhow, a little digging around suggests that you can "configure" PerlIO's buffer size in the file perlio.c:

STDCHAR * PerlIOBuf_get_base(pTHX_ PerlIO *f) { PerlIOBuf * const b = PerlIOSelf(f, PerlIOBuf); PERL_UNUSED_CONTEXT; if (!b->buf) { if (!b->bufsiz) b->bufsiz = 4096; /* <--- here */ b->buf = Newxz(b->buf,b->bufsiz, STDCHAR); if (!b->buf) { b->buf = (STDCHAR *) & b->oneword; b->bufsiz = sizeof(b->oneword); } b->end = b->ptr = b->buf; } return b->buf; }

At least, I changed that 4096 to 8192, recompiled perl (v5.10.0), and now strace reveals that read(2) is being called for blocks of size 8192, when you execute something like

open my $fh, "<", $^X or die; while (<$fh>) { }

while before the change, read blocks were of size 4096.

Other than that, I haven't done any testing yet. So, no guarantees whatsoever (!) that it'll work in every respect... — just something to play with at your own risk.  Good luck!


In reply to Re: 4k read buffer is too small by almut
in thread 4k read buffer is too small by voeckler

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.