Re: circular buffering using substr() ?
- From: "RocketMan" <rm@xxxxxxxxxxxxxx>
- Date: Mon, 04 Feb 2008 00:34:04 GMT
"arz" <azwemmer@xxxxxxxxx> wrote in message
news:022ab843-c815-4b28-a85f-089d1b005da6@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi,
Can I use substr() to do circular buffering? I'm reading a binary data
stream from a pipe, which I need to send out on another pipe, but
since speeds may differ, I need to do some intermediate buffering (up
to a maximum amount).
I have something like the following (simplified):
my $buffer = "";
my $offset = 0;
while (my $cb = read(INPIPE, my $data, 32768)) {
$buffer .= $data;
$bytes = syswrite(OUTPIPE, $buffer, $offset, length($buffer) -
$offset); # OUTPIPE is non-blocking
$offset += $bytes;
$buffer .= substr($buffer, $offset); # move buffer pointer to
offset
}
It works as intended, but the script is eating memory... is $buffer
internally actually growing and growing because it does not go out of
scope and the substr() does not 'reset' it when the new string is
assigned to $buffer? What would be the best way to do this?
Thanks,
--arz
Perl has a FIFO for just this, Named Pipe.
.
- References:
- circular buffering using substr() ?
- From: arz
- circular buffering using substr() ?
- Prev by Date: Re: circular buffering using substr() ?
- Next by Date: Re: circular buffering using substr() ?
- Previous by thread: Re: circular buffering using substr() ?
- Next by thread: FAQ 1.8 Is Perl difficult to learn?
- Index(es):
Relevant Pages
|