in reply to Re: does splice'ing an array of hashes free memory?
in thread does splice'ing an array of hashes free memory?

you're right that it's expensive. but the grep method is even slower, because the arrays are ~30000 long, and the information i "extract" from them is somewhere near the beginning of the array and their length is somewhere between 1-15. the grep method iterates to the end of the array which is what i try to prevent

my first version just splice'd it the amount of $#cvs_to_delete, it ran quick, but i can't be sure it works.

i'll try to make something that splices all consequtive rows in one sweep.

  • Comment on Re^2: does splice'ing an array of hashes free memory?

Replies are listed 'Best First'.
Re^3: does splice'ing an array of hashes free memory?
by lagle (Novice) on Nov 02, 2010 at 12:34 UTC

    here's the code i ended up for splicing subsequent indexes in one go. i have to say it saves me literally hours.

    # now we'll pop away what we found from the AoH # basically we splice out subsequent indexes in one go # and the poor lonelies have to go home alone # if nothing is to be popped, we don't pop unless (scalar @i_to_delete) { return $text; } @i_to_delete = sort {$b <=> $a} @i_to_delete; # descending order my $length = 1; my $offset = undef; for my $i (0 .. $#i_to_delete) { if ($i < $#i_to_delete) { # not the last index if (($i_to_delete[$i] - $i_to_delete[$i+1]) == 1) { # the two +are subsequent $length++; } else { # they are not subsequent, split current $offset = $i_to_delete[$i]; splice(@$AoH, $offset, $length); $length = 1; } } else { # last index $offset = $i_to_delete[$i]; splice(@$AoH, $offset, $length); $length = 1; } }