Re: circular buffering using substr() ?




"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.



.



Relevant Pages

  • Re: Design help...an explosion of interfaces......
    ... pipe is buffered are not; it is just loading or extracting from the pipe ... and call the right method with the right Pipe subclass instance. ... who understands the buffering context instantiate the relationship and ... the type attribute has a different semantics than the class ...
    (comp.object)
  • Re: circular buffering using substr() ?
    ... Can I use substr() to do circular buffering? ... stream from a pipe, which I need to send out on another pipe, but since ... $offset); # OUTPIPE is non-blocking ...
    (comp.lang.perl.misc)
  • circular buffering using substr() ?
    ... Can I use substr() to do circular buffering? ... stream from a pipe, which I need to send out on another pipe, but ... $offset); # OUTPIPE is non-blocking ...
    (comp.lang.perl.misc)
  • Re: stdout redirected to a processs own stdin
    ... Probably does not put anything in the pipe because output is buffered. ... > I suspect this is due to a misunderstanding of how pipes work. ... The UNIX system has no way of knowing about any ... turn off the output buffering with setbuf or flush the ...
    (comp.unix.programmer)
  • SUMMARY: Tru64 pipe buffer size
    ... The problem was that the application detected whether its stdout was going to file (pipe) or term, and did buffering in the case of a file. ... there was an easier way around the problem in our particular situation: Pipe the output via the tee command. ... Subject: Tru64 pipe buffer size ... We have a third-party tool which writes line-by-line to terminal device, but when its output is piped it seems to be buffering the data in chunks of approx 4KB at a guess. ...
    (Tru64-UNIX-Managers)