On Sat, Mar 14, 2009 at 10:12 AM, Peter Wu [email protected] wrote:
As in how they are organized behind the scenes.
For example, if I say
arr = [1, 2, 3, 4]
I think you meant either
arr.slice won’t work since slice requires arguments, and this is
Is it going to have to physically relocate everything after 2 in memory?
Would using a linked list be more efficient if a lot of elements are
going to be removed and inserted?
So far we haven’t done anything which would add or remove anything
arr.slice(1) simply returns a reference to the object in the second
of arr. arr is untouched
arr.slice(1,3) would return an array containing the second, third and
elements, the original array would be untouched. AND
The MRI ruby implementation of arrays uses a copy on write scheme, so
both arr and the returned object would actually share memory for the
of references. If one or the other changed then a copy would be
Ruby arrays are implemented rather efficiently both in terms of space
speed. It’s usually best to use them simply and only worry about
issues when they arise, and when they do, it will probably be something
other than “I should have used a linked list instead of an array”