From: Bob Hutchison Date: 2007-10-25T08:23:14+09:00 Subject: Re: pop/push, shift/unshift On 24-Oct-07, at 5:03 PM, Robert Dober wrote: > There remains one thing to be clarified, is this really a bug? > I do not think so, I just ran this until I got 200 points on my > terminal :-0 > > a = [] > loop do > a << Array.new( 1_000_000){ Object.new } > a.shift > $stdout.print "." > $stdout.flush > end The code in Ruby that deals with the stuff before the start of the array is non-trivial. The push(nil).pop thing I did, or the use of << you did triggers a cleanup. If you do your latest example without interleaving the << and shift you'll have a problem (change the implementation of the Thing class in my example to allocate the million element array and see what happens -- well DON'T actually, you won't like what it does to your machine). The trouble here is that the normal use of queues involves filling them up then emptying them. If you use an Array and Array.shift to empty the queue there's going to be at least one element 'stuck' in front of the array, likely more than 1. This might not matter but it might. It mattered to my cache implementation, and it mattered to Mongrel's task management. Cheers, Bob ---- Bob Hutchison -- tumblelog at http:// www.recursive.ca/so/ Recursive Design Inc. -- weblog at http://www.recursive.ca/ hutch http://www.recursive.ca/ -- works on http://www.raconteur.info/ cms-for-static-content/home/