Understanding Monotouch under the hood? - 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?

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.

Related

AccessViolationException when using WP8.1 MapControl.SetLocation() method

I'm developing Windows Phone 8.1 WinRT application (Universal App), which is based on MapControl control.
The problem with it is that, for unknown reasons to me, when I call MapControl.SetLocation() method, I get AccessViolationException. It does not always happen - in fact I've been using that method for quite a long time and everything was fine. But now I'm developing new functionality - it boils down to porting code from MSDN (pushpin clustering) - MSDN Sample. Code contains some callback logic, some async/await usages. The problem is in mentioned earlier SetLocation(). I don't know why it throws exceptions.
What I've tried:
I'm working with MVVMLight, so experimented a lot with DispatcherHelper.CheckBeginInvokeOnUI(). Nothing.
Tried to make sure whether creating the pushpin object happens in UI thread - I don't know how to do that in the debugger (shall I check the tasks windows, or the threads window).
I don't post any code, because, as you can imagine, it's quite a lot of it - and I don't know if that would be any of use. So, my question is, do you know what might cause throwing AccessViolationException when invoking CheckBeginInvokeOnUI? Maybe there are some kind of constraints that I'm not aware of.

Catel application initialization

I'm looking into Catel. I started following along in the Getting Started for WPF Developers. I create the initial project using the template and run it. All well and good.
Then I take a detailed look at the generated source files. I see references to DataWindow, StyleHelper, and ViewModelBase. And I run in the debugger and watch the Catel debug output, stepping so that I can see when things happen.
And it is all magical.
The view manager somehow runs and registers the MainWindow. And the ViewModelFactory is invoked to create MainWindowViewModel, and the MainWindow DataContext gets set.
How does this all happen? I am missing the documentation that puts together for me the sequence of events when an application starts. I am reluctant to take it on faith, and reluctant to dive into the giant code base without an inkling of where to start. I have read the CodeProject articles and the intro part of the documentation.
Is this driven off of the behaviors some way? How are they invoked? I just can't find the thread that starts me on my way.
Aside: I look at Catel because I found myself implementing a ton of plumbing for a significant MVVM application, and decided that someone else had already solved this problem.
Thanks for any leads. (And thanks, Geert. This is a significant work.)
-reilly.
If I understand correctly, you are looking for advanced information of the inner workings. I think this part of the documentation might be of interest for you.
It might not provide all information you are looking for, but it should provide some.
About some basic questions:
1) The startup windows is defined in App.xaml (that's standard WPF)
2) Since it derives from DataWindow, it uses WindowLogic => LogicBase. The LogicBase uses the IViewModelLocator to find the right view model based on naming conventions (all documented)
3) Then the IViewModelFactory will instantiate the vm (using dependency injection) and return it to the logic which will set it as datacontext.
Note that as the advanced documentation tells you, Catel injects an additional layer to make a difference between the outside datacontext and the VM datacontext (of a window or user control content).
ps. I really recommend starting to use the latest prereleases via NuGet. Catel 4.0 (will be released very soon) is nearly feature complete and will prevent you from a lot of breaking changes that you have to go through (and it is of course much better :-))

OpenCL quasi-quoting

I'm looking for a way to use OpenCL nicely in Haskell, and found these slides (alternative source) by Benedict Gaster. They mention an impressive “HOpenCL Contextual API” but I can't find anything tangible.
The only thing coming close to the C quasiquotation shown seems to be language-c-quote and its OpenCL-C support ends with the types, it doesn't support the extra keywords.
And accelerate is something completely different, and mainly for CUDA, with the OpenCL backend in early alpha.
Then there's HIPERFIT where no code was posted for a year (but the project is still running), which seems to combine the C quasiquotation and OpenCL, their bindings are even called HOpenCL, but are just a wrapper, nothing to see of the monadic transforms etc.
None of this seems close to finished and ready to build upon…
Any news or other projects I missed?
I was looking for exactly the same thing, and I came across this: https://github.com/bgaster/hopencl
This must be what Benedict Gaster - who is not working for AMD anymore - was talking about. There is not a tremendous amount of activity on the git, but there was an update about 2 months ago, which is still better than a year.
EDIT: Actually J. Garret Morris (the other author of HOpenCL) created a fork: https://github.com/jgbm/hopencl
First seeing you post here now. I'm the author of the HIPERFIT-hopencl package and sort of also a bit responsible for the language-c-quote OpenCL C support. I apologize for the naming confusion and that we now have two hopencl-packages. I have mailed Benedict Gaster and J. Garret Morris about how we resolve that.
What do you find lacking in language-c-quote? Could you give an example of what OpenCL C code that it doesn't handle?
(PS. I'm new here and could not find a way to comment on your post, so I had to post this as an answer - perhaps I just haven't reached the right "clearing level" yet)

Using Dapper in MonoTouch

Since I'm a big fan of Dapper and using it for a couple SQL Azure Projects I would like to use on MonoTouch as well against the built-in Mono.Data.SQLite.
I realize that Dapper's speed comes from the dynamic code generation which unfortunately is a big no-no on iOS where everything has to be compiled ahead-of-time by MonoTouch.
First question: Has anyone made any efforts to provide reflection based implementation of the relevant parts of dapper? (I know it will be a LOT slower) If not how hard would it be to implement it (only glanced over the Dapper source).
Second question: I hope I am not sounding naive here but would it be remotely possible to write a little utility that would materialize the dynamically generated IL for your entity POCOs into an IL assembly source file that could be added to your MonoTouch project and thus gets AOTed during build time? Or is this impossible due to joins and QueryMultiple etc?
Note: I realize there is at least one attempt to port Dapper to MonoTouch but glancing over the source I have no idea how's that supposed to fly since all the dynamic method generation stuff is still in there.

Guidance on broadening horizons

Let me setup my question with some info. I'm not in college yet and strictly a hobby programmer. Probably a little more than 2 years ago I got started programming on mac. I started with very simplistic GUI examples with Cocoa and XCode. Long story short, I learned from the top down, first learning objective-c, then venturing into more "low-level" projects where I became better at basic C and even used a few C++ libraries in my existing projects.
What I'm saying is that I've never really done anything outside of an XCode project and occasional iPhone project. I've implemented lots of stuff, algorithms, math, etc. but all within that environment. I look at the world of programming and there is so much out there that's not necessarily a standalone application. It seems to me that the hardest thing is finding out where to start; how to setup the environment. I guess I'm wondering if anyone has any suggestions, projects, tutorials, maybe on setting up environments for different languages on different systems. Web programming, java applets? etc.
On the note of environments, I would be interested in knowing on a more basic level what makes a "development environment." To my basic knowledge, an "environment" combines the language, with the compiler that interprets that language, and contains libraries that provide an API for the language, where the compiled product runs on a certain system. This is my basic concept, but again, I'm here.
Sorry if this question... well... combines too many questions, but any input or guidance is welcome. Thanks in advance for any replies!
Not sure if I understood your question correctly or if this will help you, but here are my (relative newbie) thoughts and rambling:
I've done Java at uni in two different courses, one where we wrote the code in Notepad and then compiled it in command line, in some dubious DOS application, and then two years later when we worked in NetBeans and while NetBeans was a lot better and easier, I learned a lot and was a lot more careful when writing code after the Notepad experience (especially after waiting for several minutes for a compile only to see a message caused by a silly bug).
If you can choose between IDEs, I would read on different blogs, see what people prefer and why and make a choice. The problem is that most of the time, both at uni and at work, you can't choose and have to go with the teachers/managers choose, and make the best of it.
It seems to me that the hardest thing is finding out where to start; how to setup the environment.
I think it would be easiest if you found something that you want to do, and then take small steps and get bits done. I work as a desktop app developer and 3 years ago I set up a wordpress blog for a friend and imported posts and comments from a different blogging platform, with minimal knowledge about everything involved. I started with things that were already done by others and learned how to use them and then slowly tried to fill in the gaps - the comments part wasn't done then, so I had to learn about databases, how I could see them and then write the code that inserted in them, etc.
What I'm trying to say is that if you find something to do (and if you don't have ideas for projects, you can find several posts with ideas here, on SO) and then set goals towards doing that, even if you don't finish it, or your studying takes you in areas you hadn't expected, it will all be useful at some point.
I guess I'm wondering if anyone has any suggestions, projects, tutorials, maybe on setting up environments for different languages on different systems. Web programming, java applets? etc.
This is way too broad a question. If you're doing web programming, you need to set up a web programming environment. At a minimum, you would need an HTTP server. You'd probably also need a relational database. The rest of the web environment would be language dependent.
If you're doing GUI programmng, you would need access to the device or devices (iPhone, Android, etc.) that you want to write programs for.
To my basic knowledge, an "environment" combines the language, with the compiler that interprets that language, and contains libraries that provide an API for the language, where the compiled product runs on a certain system.
That gets you started, yes. You'd want an integrated development environment to write the code. Again, you'd probably need a relational or object oriented database. The rest of the development environment is language dependent.

Resources