Setting perl's output buffer size

I

Itay Greenspon

Hi,

When printing to an output handle, buffering varies with the type of
output device.
From the perl cookbook:
"Disk files are block buffered, often with a buffer size of more than
2K. Pipes and sockets are often buffered with a buffer size between
1/2 and 2K. Serial devices, including terminals, modems, mice, and
joysticks, are normally line-buffered; stdio sends the entire line out
only when it gets the newline."


There's a simple mechanism to enable autoflushing (using $| or
otherwise) ,
But can one control the SIZE of the output buffer?
(rather than setting buffering "on"/"off")

-- Itay
 
B

Ben Morrow

Quoth Itay Greenspon said:
When printing to an output handle, buffering varies with the type of
output device.
"Disk files are block buffered, often with a buffer size of more than
2K. Pipes and sockets are often buffered with a buffer size between
1/2 and 2K. Serial devices, including terminals, modems, mice, and
joysticks, are normally line-buffered; stdio sends the entire line out
only when it gets the newline."


There's a simple mechanism to enable autoflushing (using $| or
otherwise) ,
But can one control the SIZE of the output buffer?
(rather than setting buffering "on"/"off")

Why do you want to? The buffer is chosen to be an appropriate size to
get efficient IO.

With perls before 5.8, you can use IO::Handle::setvbuf to set the size
of stdio's buffers. After 5.8 perl doesn't use stdio by default, so the
size of the buffer cannot be set. If you have a need to control the
buffering that accurately, you are best off opening the file with a
:unix layer (see perldoc PerlIO) to get unbuffered IO, and doing the
buffering yourself.

Ben
 
I

Itay Greenspon

Quoth Itay Greenspon <[email protected]>:





Why do you want to? The buffer is chosen to be an appropriate size to
get efficient IO.

With perls before 5.8, you can use IO::Handle::setvbuf to set the size
of stdio's buffers. After 5.8 perl doesn't use stdio by default, so the
size of the buffer cannot be set. If you have a need to control the
buffering that accurately, you are best off opening the file with a
:unix layer (see perldoc PerlIO) to get unbuffered IO, and doing the
buffering yourself.

Ben

Thanks ben, I'll try the unix layer.
btw,
I need this because I'm using a custom (non standard) IO device.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top