[Melbourne-pm] Timer::HiRes and alarms?

Alfie John alfiejohn at gmail.com
Fri Nov 12 02:29:08 PST 2010

On Fri, Nov 12, 2010 at 11:05 AM, Jacinta Richardson <
jarich at perltraining.com.au> wrote:

> Alfie John wrote:
>  Be careful to think that this is absolutely true. Perl's arrays are not C
>> arrays. If your index is greater than the number of elements in the array,
>> then the array will be extended i.e. the array element pointers will be
>> copied into a new array which can hold just one more element. This will
>> happen *each time* you extend the size of an array i.e. push()!
> This is not completely correct.  When you create an array in Perl, Perl
> creates a hunk of memory for it and puts the array in the middle.  If you
> unshift or push things onto the array they bring the start or end of the
> array closer to the boundaries of the memory Perl put aside for you.  If you
> get "too close" to either end, then Perl allocates twice as much space for
> you (as it did the first time) and copies your array into the middle of
> that.  You can then add to the start or end of the array at will until you
> again get "too close" to one of the ends; wherein Perl gives you more space
> again.

I remember years ago someone saying something along the lines that unshift()
was more expensive than push() so at the time I had a cursory look at how
Perl implemented arrays. My explanation above was how I understood the code
at the time. Looking again tonight I can see that I was wrong! Sorry Daniel
and thanks Jacinta for picking that up :)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/melbourne-pm/attachments/20101112/5658555e/attachment.html>

More information about the Melbourne-pm mailing list