in reply to Re^4: how to read multiple line from a file
in thread how to read multiple line from a file

> This leads to extra memmove()s if you're lucky (I believe Perl does this),

Sure but I think we should try and measure before we optimize.

> and endless memory consumption otherwise.

Why? Someone .. (I think Grandfather) said once linked lists are rarely needed in Perl, because arrays are optimized in this way.(?!?)

Anyway having an array were the newest line is somewhere in the middle results in arithmetical overhead.

Slicing and copying this array in a sorted one leads to new overhead.

I think try and measure is easier than digging into theoretical calculations...

Cheers Rolf

( addicted to the Perl Programming Language)

  • Comment on Re^5: how to read multiple line from a file

Replies are listed 'Best First'.
Re^6: how to read multiple line from a file
by educated_foo (Vicar) on Apr 14, 2013 at 20:56 UTC
    I think try and measure is easier than digging into theoretical calculations...
    This has nothing to do with theory. An array is a contiguous chunk of memory. If you put things on one side and take them from the other, you can either shift the current contents, or keep allocating more memory.
    Just another Perler interested in Befunge Programming.
      > This has nothing to do with theory.

      Nonsense! Sorry!

      Taking a short look into the Panther book convinces me that your understanding of AVs is rather oversimplified¹!

      There are mechanisms to optimize the effects of shifts and pushs!

      Anyway others are more qualified to talk about perlguts.

      Cheers Rolf

      ( addicted to the Perl Programming Language)

      ¹) this is not C !

        Or you could just look at av.h. How do you think xav_alloc works?
        Just another Perler interested in Algol Programming.