in reply to How to implement a Queue that doesn't leak memory?

Creeping forward is not referring to memory leak. What its referring to is the need from time to time for perl to re-allocate memory (which is slow).

Example: Say you have 16 element array a(16). Internally perl will have a(32) and be using 8 to 23 for your 16 spots. This is so push and unshift can work extremely quickly - as there is already allocated space for them (position 7 for unshift, 24 for push)

However if perl is using 8 to 23, and then you push and then unshift, perl is now using 9 to 24. Then 10 to 25. etc. So internally to perl, the array "creeps forward". Eventually, Perl has to either move everything back down (to 8 to 23), or re-allocate (change a(32) to a(64)).

The author is talking about how while most push/pop/shift/unshift is going to work very quickly, occasionally 1 will be slow, while perl performs this internal work.

  • Comment on Re: How to implement a Queue that doesn't leak memory?