Array slicing through a reference: Inefficient?

Ask a Question related to PERL Miscellaneous, Design and Development.

  1. #1

    Default Array slicing through a reference: Inefficient?

    Dear Group--

    I'm working on a project where I'm working with large arrays, and I'm
    using references to pass arrays around to reduce memory use as much as
    possible. I often work with small subsets of a referenced array and
    access it like:

    my @subrange = @{$big_array_ref}[$start_idx .. $end_idx];

    Also, to get the array size, I'll do:

    my $num_points = @$big_array_ref;

    Is this the best practice? Do I need to be concerned in a statement
    like

    @{$big_array_ref}[$start_idx .. $end_idx];

    that the array referenced by $big_array_ref is being completely copied
    before the subrange is taken? Likewise for the $num_points example.

    Thanks,

    --Ethan Brown
    --Keyboards: "The Fabulous Pelicans" ([url]www.pelicans.com[/url])
    --In a band? Use [url]http://www.WheresTheGig.com[/url] for free.

    Ethan Brown Guest

  2. Similar Questions and Discussions

    1. Array Reference
      This loop does not seem to like the reference to the array via application.production.getWorkLoad() where i is the index. Is there a way to...
    2. Can't reference array that exists....i checked!
      Scenario: frame 1 i create array called xml_array; I then fill array with other arrays, creating a 2 dimensional array. easy enough. So i...
    3. list ($d, $row) = each ($array) by reference?
      Hi ! I always thought that while (list($d,$row) = each($array)){ $row = 5; } would operate by reference, so that $array is filled with 5...
    4. Array Reference Practice Help
      Is this a standard/normal/ok way to pass and use array by reference? @alpha=("a","b","c"); @numer=(1,2,3); #calling by reference...
    5. Couple of array/reference type questions
      There are several array type things I find myself doing all the time and I'd like to know, once and for all, the best way to do them. For the...
  3. #2

    Default Re: Array slicing through a reference: Inefficient?

    Also sprach Ethan Brown:
    > I'm working on a project where I'm working with large arrays, and I'm
    > using references to pass arrays around to reduce memory use as much as
    > possible. I often work with small subsets of a referenced array and
    > access it like:
    >
    > my @subrange = @{$big_array_ref}[$start_idx .. $end_idx];
    >
    > Also, to get the array size, I'll do:
    >
    > my $num_points = @$big_array_ref;
    >
    > Is this the best practice? Do I need to be concerned in a statement
    > like
    >
    > @{$big_array_ref}[$start_idx .. $end_idx];
    >
    > that the array referenced by $big_array_ref is being completely copied
    > before the subrange is taken? Likewise for the $num_points example.
    There is no need to worry here. If you have a reference to an array,
    this means that the actual array also exists somewhere and you just
    happen to access it through a reference. You're not duplicating any
    arrays and no temporary huge arrays are built either.

    Tassilo
    --
    $_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
    pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus}) !JAPH!qq(rehtona{tsuJbus#;
    $_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexi ixesixeseg;y~\n~~dddd;eval
    Tassilo v. Parseval Guest

  4. #3

    Default Re: Array slicing through a reference: Inefficient?

    In article <vr1xufl44l.fsf@draupnir.gso.saic.com>,
    Ethan Brown <ethan@draupnir.gso.saic.com> wrote:
    > Is this the best practice? Do I need to be concerned in a statement
    > like
    >
    > @{$big_array_ref}[$start_idx .. $end_idx];
    >
    > that the array referenced by $big_array_ref is being completely copied
    > before the subrange is taken? Likewise for the $num_points example.
    As far as I know - but I haven't read the friendly source - the array is
    not copied. In other words you're saying to perl "give me the slice
    $start to $end from the array _pointed to_ by $arrayref". So I'd say to
    you: don't worry , I think you're doing things the right way

    P

    --
    pkent 77 at yahoo dot, er... what's the last bit, oh yes, com
    Remove the tea to reply
    pkent Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139