Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding Monotouch under the hood?

Tags:

xamarin.ios

I read a lot about how MT works, that it binds to the iOS's API, that it uses AOT compiling, that there is no .NET runtime on the iPhone and so on.

Geoff once wrote this in an answer to one of my questions, which shows how to bind an ObjC selector:

var url = new NSUrl ("http://www.google.com/");
var str = (NSString) Runtime.GetNSObject (Messaging.IntPtr_objc_msgSend_IntPtr (Class.GetHandle ("NSString"), Selector.GetHandle ("stringWithContentsOfURL:"), url.Handle));

But what is happening under the hood if I do this? And does that mean if I use a call that is already bound, it will execute something similar like the code above in the background, hiding it from me? Does it mean that everytime some Selector.GetHandle() and Runtime.GetNSObject() is executed?

How has the whole MT project been started? At some point the team must have been there thinking, "we have ObjC here and Mono there - how can we combine them?" I mean, what was the first thing that was done, tried?

And one last thing about the garbage collector: I assume it has to run in a separate thread - but is it really ONE thred? Or are there several? How does the GC collector decide that it is time to clean up?

like image 559
Krumelur Avatar asked Nov 06 '22 02:11

Krumelur


1 Answers

Alot of what MonoTouch does is exactly what Mono does on other operating systems.

They started with a subset of the .Net BCL: Silverlight, and also bound the Objective-C apis on the iPhone. They also probably created the AOT compiling option, as I would assume this is the first situation that needed it. Apple required (or strongly preferred) that no one would abstract, or put a layer on top of their APIs. So far MonoTouch, is the only framework that has succesfully done this to bring a new language to the iPhone.

To read some of the more interesting details, check there documentation here. When I first started working with MonoTouch, I read every bullet point under the Documentation heading, as all were pretty interesting and in-depth.

Another resource that you might get more answers than stackoverflow is at their IRC chat. Here is a link to a web-based version, if you don't want to mess with IRC.

like image 97
jonathanpeppers Avatar answered Nov 20 '22 19:11

jonathanpeppers