Perl Large Scalar Question?

Discussion in 'Perl Misc' started by Bob Mariotti, Jun 8, 2004.

  1. Bob Mariotti

    Bob Mariotti Guest

    Here's one for the perl internals guru's:

    We have a module that is used by many programs in our suite.
    Currently it works and has been working just fine for several years.

    What it does is take a string that is passed to it and sends it out a
    tty port to a remote host then it enters into a read loop
    contatenating all returned records until it receives one beginning
    with "0999". Here is a sample snippet (NOT ACTUAL CODE)

    >$DATA="";
    >open(XXX,"+>/dev/ttyxxxx") or die $!;
    ># Send Request to host
    >print XXX "$Message\015" or die $!;
    ># Get Response from host
    > while (<XXX>) {
    ># Exit if Last Record Signal
    >if (m/^0999/) { last; }
    ># Contruct Host Response String
    >$DATA.=$_;
    >}
    >return $DATA;


    If the very most cases this works just absolutely fine as the records
    coming back are either one or a few or at most a dozen or two.

    However, we've added a request that will return upwards of 1000+
    records of 115 bytes each. The time to execute is becoming
    unacceptable and my thought is that the reallocation of the scalar
    variable $DATA is costing too much in time and resource.

    Is there any good way to preallocate that scalar to approx 1000 x 115
    before entering the loop so the re-allocation, data content move, and
    destruction of the old scalar doesn't have to happen????

    Also, can anyone recommend a more efficient method for obtaining and
    passing these/this data back to the calling routine???

    Thanks all.

    Bob Mariotti
    "perl is great!"
    Bob Mariotti, Jun 8, 2004
    #1
    1. Advertising

  2. Bob Mariotti

    thundergnat Guest

    Bob Mariotti wrote:

    >
    > However, we've added a request that will return upwards of 1000+
    > records of 115 bytes each. The time to execute is becoming
    > unacceptable and my thought is that the reallocation of the scalar
    > variable $DATA is costing too much in time and resource.


    Unfortunately, I would suspect that the tranfer of 115000 bytes of data
    over a serial link is going to be three or more orders of magnitude
    slower than allocating 115000 bytes of space in memory. It sounds like
    you are trying to optimize the wrong thing.

    You would likely get more bang for your buck trying to transfer the data
    in larger blocks, compressing the data before it is sent, or using a
    faster transport method. Not knowing the particulars of your
    application, it is difficult to make any really useful observations.
    thundergnat, Jun 8, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jack Dowson
    Replies:
    1
    Views:
    289
    Chris Dollin
    May 1, 2007
  2. Eric Mahurin
    Replies:
    4
    Views:
    231
    David A. Black
    May 6, 2005
  3. Mike Mimic
    Replies:
    1
    Views:
    202
    Mike Mimic
    Sep 28, 2003
  4. Clint Olsen
    Replies:
    6
    Views:
    333
    Jeff 'japhy' Pinyan
    Nov 13, 2003
  5. Mark

    Replace scalar in another scalar

    Mark, Jan 27, 2005, in forum: Perl Misc
    Replies:
    4
    Views:
    144
    Arndt Jonasson
    Jan 27, 2005
Loading...

Share This Page