mail-archives/mono-osx/2006-December/000715.html

149 строки
6.9 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE> [Mono-osx] There Bool Dragons Here
</TITLE>
<LINK REL="Index" HREF="index.html" >
<LINK REL="made" HREF="mailto:mono-osx%40lists.ximian.com?Subject=%5BMono-osx%5D%20There%20Bool%20Dragons%20Here&In-Reply-To=210C6054-62AE-44F5-8E56-7B9DEF26F892%40bleepconsulting.com">
<META NAME="robots" CONTENT="index,nofollow">
<META http-equiv="Content-Type" content="text/html; charset=us-ascii">
<LINK REL="Previous" HREF="000714.html">
<LINK REL="Next" HREF="000717.html">
</HEAD>
<BODY BGCOLOR="#ffffff">
<H1>[Mono-osx] There Bool Dragons Here</H1>
<B>Allan Hsu</B>
<A HREF="mailto:mono-osx%40lists.ximian.com?Subject=%5BMono-osx%5D%20There%20Bool%20Dragons%20Here&In-Reply-To=210C6054-62AE-44F5-8E56-7B9DEF26F892%40bleepconsulting.com"
TITLE="[Mono-osx] There Bool Dragons Here">allan at counterpop.net
</A><BR>
<I>Sat Dec 16 20:05:34 EST 2006</I>
<P><UL>
<LI>Previous message: <A HREF="000714.html">[Mono-osx] There Bool Dragons Here
</A></li>
<LI>Next message: <A HREF="000717.html">[Mono-osx] Mono and Obstufcation on OSX
</A></li>
<LI> <B>Messages sorted by:</B>
<a href="date.html#715">[ date ]</a>
<a href="thread.html#715">[ thread ]</a>
<a href="subject.html#715">[ subject ]</a>
<a href="author.html#715">[ author ]</a>
</LI>
</UL>
<HR>
<!--beginarticle-->
<PRE>
On Dec 16, 2006, at 3:53 PM, R. Tyler Ballance wrote:
&gt;<i> This is a Dumbarton related question, there will surely be many to
</I>&gt;<i> follow :)
</I>&gt;<i>
</I>&gt;<i> 1)
</I>&gt;<i> I'm curious as to how &quot;safe&quot; DB_BOX_BOOLEAN is, from my
</I>&gt;<i> understanding with p/invoke code, booleans are tricky as they tend
</I>&gt;<i> to be represented differently on a variety of different
</I>&gt;<i> architectures, should I write my wrapper code using int values of
</I>&gt;<i> 0, and -1, or can I safely rely on bool to not &quot;screw things up
</I>&gt;<i> royally down the line&quot;
</I>
It should work fine as long as you're treating your booleans as BOOL
types in ObjC. Mono's booleans are of type &quot;MonoBoolean&quot;, which are
just typedef'd unsigned chars. The BOOL type in ObjC is a signed
char, but I think that any sane thing you do should work with the
standard C &quot;zero or not zero&quot; boolean logic.
&gt;<i> 2)
</I>&gt;<i> From the best of my understanding there's no way to have events
</I>&gt;<i> traverse into notifications of some sort on the other side of the
</I>&gt;<i> bridge, and I'm wondering what other 'notification' methods might
</I>&gt;<i> be possible, such as calling function pointers (i.e. how async I/O
</I>&gt;<i> in C can be achieved), etc. I'm going to have a few threads running
</I>&gt;<i> in the C# core that would need to notify the native Cocoa UI
</I>&gt;<i> through some means when things long extended (non-blocking) network
</I>&gt;<i> I/O calls are finished. Suggestions?
</I>
There *should be* (but isn't) a simple way to do this by doing some
C# event bridging magic in Dumbarton. The current solution that we
use at imeem is to register internal calls for event-firing functions
that can be called from C#. The implementing code on the non-managed
side then takes the arguments to the event and packages them into an
NSNotification, which gets queued asynchronously onto the main thread
through an NSNotificationCenter. From that point, ObjC code just
observes the notification like any other Cocoa-style notification. It
would probably be possible to write code in Dumbarton to emit code at
runtime that allowed you to subscribe a dynamically generated managed
wrapper delegate to a C# event, but I don't have the time to look
into this, and nobody else has needed anything like this...:)
&gt;<i> 3)
</I>&gt;<i> Memory management (insert pause here to allow cringing where
</I>&gt;<i> appropriate). While Objective-C 2.0 may have garbage collection, am
</I>&gt;<i> &quot;I responsible&quot; for taking care of my DBMonoObjectRepresentation
</I>&gt;<i> subclasses in terms of releasing them where appropriate, and then
</I>&gt;<i> just let the C# code garbage collect as per usual in wholesale Mono
</I>&gt;<i> applications? Are there any caveats to &quot;standard&quot; memory management
</I>&gt;<i> with Cocoa that I should be aware of before I unleash memory leaks
</I>&gt;<i> a'plenty upon my code base? ;)
</I>
As long as you properly retain/release your wrapper objects, you
should be fine. A leaked ObjC wrapper object means the underlying C#
object is also leaked. If, for some reason, you keep around unwrapped
C# object references in ivars, you'll need to either register gcroots
or create a GC handle for those objects or they will be collected out
from under you.
There are no guarantees that ObjC-2.0 garbage collection will be
possible with Dumbarton. The interaction between the two garbage
collectors will be... interesting. It may be possible, but maybe not.
Another thing to worry about is that if the two GCs play nicely with
each other, you now have two different GCs routinely suspending your
threads and walking their stacks... not exactly a formula for good
interactivity. I talked to one of the creators of the new GC at WWDC
and it looks like it might be possible to make Mono use the new GC
instead of libgc or sgen (with some caveats), but I haven't tried
actually doing this with the 10.5 DP.
[...]
&gt;<i> I really can't thank you imeem guys enough for Dumbarton, this
</I>&gt;<i> project I'm working on right now involves:
</I>&gt;<i> - Custom network libraries implemented in C
</I>&gt;<i> - C# core with sporadic calls out to platform dependent code
</I>&gt;<i> - native Cocoa interface with plenty of pretty AppKit subclasses
</I>&gt;<i>
</I>&gt;<i> Without Dumbarton, tying all this together would fall under the
</I>&gt;<i> &quot;clusterfuck&quot; umbrella, where it stands now, it's just in the
</I>&gt;<i> &quot;wtf?&quot; camp :)
</I>
It's good to see other people are getting use out of Dumbarton.
-Allan
--
Allan Hsu &lt;allan at counterpop dot net&gt;
1E64 E20F 34D9 CBA7 1300 1457 AC37 CBBB 0E92 C779
</PRE>
<!--endarticle-->
<HR>
<P><UL>
<!--threads-->
<LI>Previous message: <A HREF="000714.html">[Mono-osx] There Bool Dragons Here
</A></li>
<LI>Next message: <A HREF="000717.html">[Mono-osx] Mono and Obstufcation on OSX
</A></li>
<LI> <B>Messages sorted by:</B>
<a href="date.html#715">[ date ]</a>
<a href="thread.html#715">[ thread ]</a>
<a href="subject.html#715">[ subject ]</a>
<a href="author.html#715">[ author ]</a>
</LI>
</UL>
<hr>
<a href="http://lists.ximian.com/mailman/listinfo/mono-osx">More information about the Mono-osx
mailing list</a><br>
</body></html>