[Rubydotnet-developer] rubydotnet - first announcement
Status: Alpha
Brought to you by:
thomas
From: Thomas S. <th...@th...> - 2003-09-03 21:16:55
|
This is a repost as my first email seems to have dissappeared. If you got the first one, please ignore this one :-) Hi, I've made some progress with my own rubydotnet project. Instead of using sockets for communication or hosting the CLR, my module is written as a managed C++ extension. With this approach I have managed to get the basic functionality running with 245 lines of C++ code and 50 lines of ruby. One of the things that I have done differently is the class discovery. Instead of using a DotNet object as root for the hierarchy I'm using the new Module#const_missing feature in ruby-1.8.0, which means that I can do something like this: require 'dotnet' include System.Collections a = ArrayList.new a.count # => 0 a.add(1) a.count # => 1 I've also got a Kernel::reference() method you can call to reference whatever assemblies you may want to use. Next I'll add delegates that invoke ruby and.net interface implementation in ruby. This should be relatively straightforward. I'm worried about .net class inheritance from ruby, though, from a garbage collection stand point. When I pass a ruby object to .net I wrap it in a RubyDotNet::Object .net wrapper and vice versa with .net objects that are passed to ruby. These wrappers lock the wrapped objects from being garbage collected using rb_gc_register_address on the ruby side an System::Runtime::InteropServices::GCHandle on the .net side. If you inherit a .net class from ruby you will need the ruby object and the .net object to reference each-other, but then they will be locked in memory and will never be garbage collected. I'm aware that this is just a special case of a cyclic reference problem that exists with my approach, but it is not too likely to bite you in most other cases. How have you guys addressed this problem? Do you have any idea about how to handle this problem? Have you made any progress on the thread safety issue with callbacks from .net to ruby? I'm wondering if it is necessary to make some kind of synchronized queue, where you post you callbacks and then have a pool of ruby threads reading the jobs from that queue as they are posted. Or maybe we could lobby match to add some locking to ruby to make it thread-safe? I know too little about this :-) Cheers, Thomas |