Hey all! This is my first post here, although I’ve been involved via proxy for awhile through Raydred. He also talked me into getting on the Tetris top-ten score list in the arcade (some mad tetris genius seems to have the top spot). Anyway, I thought I’d pick your collective brains about something:
How does the Flash VM implement the Array.Unshift method?
I’m implementing a Circular Buffer old-school style (ie, allocating an array and having pointers for the head and tail elements in the array). However, since Flash offers Unshift and Pop methods, it’s possible to implement a dynamically sized circular buffer by Unshifting new values onto an Array as they come in and Popping them off when needed. This interests me, as it seems easy and dynamic, but those same things make me worried about speed lol.
Has anyone tested performance of the Unshift method? Does it get slower as the array grows? Is it basically moving each element of the array ‘over’ by one then setting the first element, or is Macromedia more clever than that?
I’m mostly interested from a theoretical point of view, because I over-optimize everything when I can. I’d hate to use Unshift in an inner loop if it’s actually slow.