From: Randy Kramer Date: 2005-04-05T06:14:27+09:00 Subject: Re: doubly linked list in Ruby? On Monday 04 April 2005 03:44 pm, Douglas Livingstone wrote: > On Apr 4, 2005 8:39 PM, Randy Kramer wrote: > > But (just asking), what about performance? Is an entire new array > > created, or is the new stuff (only) put in a newly allocated piece of > > memory and a pointer/reference/whatever inserted into (maybe a linked > > list which implements) the array? > > irb(main):001:0> a = [1,2,3] > => [1, 2, 3] > irb(main):002:0> b = a > => [1, 2, 3] > irb(main):003:0> b[2,0] = 4 > => 4 > irb(main):004:0> a > => [1, 2, 4, 3] > irb(main):005:0> b > => [1, 2, 4, 3] > irb(main):006:0> a == b > => true > > [] is sugar for Array.new, they are objects like any other. Douglas, Thanks! (I should have tried that myself.) And, I've now done so, throwing in several a.id and b.ids. Looks like it's the same array (the same object) before and after, so, I think that means the new value is linked in. (Presumably, if the array had to be rewritten to be expanded, the object would have a new id (i.e., address), iiuc.) regards, Randy Kramer