[MacRuby-devel] thread-safety and collections in macruby

Chuck Remes cremes.devlist at mac.com
Wed Oct 19 08:06:33 PDT 2011


On Oct 19, 2011, at 12:41 AM, Terry Moore wrote:

> If you're not wring/changing the array no problems. But to be safe use Object#freeze...
> 
> Terry Moore
> 
> On 19/10/2011, at 6:26 PM, Michael Johnston <lastobelus at mac.com> wrote:
> 
>> Note, in my example I can also guarantee that none of the elements in b are going to be changed (for example, an array of strings)

Object#freeze is a terrible method. Supporting it requires an extra check (#frozen?) in every method that tries to modify an object. This is why Ruby is slow (certainly not the only reason, but decisions like this are everywhere). 

:)

Using #freeze won't save you but it will throw a RuntimeException if you try to modify a frozen object. So it's really only good for pointing out that you have a bug when you attempt to modify your immutable array.

cr




More information about the MacRuby-devel mailing list