Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
536 views
in Technique[技术] by (71.8m points)

cross platform - How MonoTouch works?

I would really appreciate it anybody could briefly explain me, what's the general approach to implementing things like MonoTouch? I'm really amazed because it's not the first example I see when people get some platform like Java and make it translate into something like C/Objective-C. I can't really imagine how things like Garbage collector and stuff are being translated.

Thanks in advance.

EDIT: I understand theoretical possibility of translating one language into another. My question is a bit more technical: do they implement a complete runtime in ObjC and bundle it? (I doubt it...) Or they just translate C# code into ObjC/binary/etc?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

MonoTouch isn't a translator. It's simply the Mono runtime running on iPhone, with some fancy trickery to make it compatible with the iPhone's restrictions.

The conventional Mono "runtime" isn't just the JIT, it also handles GC, reflection, I/O layer, threading, exceptions etc. There's also the class libraries. In order for your app to run on the iPhone, much of this must be included with the app. Slimming it down presents some challenges. In addition, the iPhone prevents JIT runtime code generation, only runs signed code, and doesn't allow dynamic libraries.

What MonoTouch does is to use an IL linker to combine just the parts of the class libraries that your code uses into a single IL binary. It then uses AOT compilation to pre-generate all the native code that the JIT would normally generate from the IL, then links this together with the JIT-less runtime into a single native binary that can be signed. Finally, the IL is stripped from the managed binary. leaving only metadata.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...