A
arz
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
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