Thanks. Since there are a lot of options I'm going to do a benchmark to compare them. For my particular workload, the problem is a "changing gears" sort of problem, where I need to collect an aggregate result to the ui. Since the worker loop is pretty consistent in the time each iteration takes, but results are random, I will test the idea of using a lazy lock, where the worker collects results in an array only the worker accesses and dumps them to the array the UI updater can access every X times through the loop (or by time, if that benchmarks better). Cheerio, Michael Johnston lastobelus@mac.com On 2011-10-19, at 8:28 AM, Matt Aimonetti wrote:
The proper way to protect mutable objects is to use a mutex: http://www.ruby-doc.org/core-1.9.2/Mutex.html
- Matt
Sent from my iPhone
On Oct 19, 2011, at 8:06, Chuck Remes <cremes.devlist@mac.com> wrote:
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@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
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel