Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embedded Mono: Keeping references to C# objects in C++

Tags:

c++

c#

mono

I'm working on embedding mono into an application I'm creating, and I haven't gotten super far, but one of the things I can't seem to find is how to tell mono when I'm using an object and done with an object.

I want to keep a reference to a C# object to call methods on until the lifetime of it's parallel object in C++ is over, at which point, I want to tell mono that the C# object is safe to collect.

How is this accomplished?

like image 906
Jeff Avatar asked Dec 04 '11 03:12

Jeff


1 Answers

It appears that what I'm looking for is mono_gchandle_new, and hold onto the handle, not the MonoObject*, and use mono_gchandle_get_target when I need it.

mono_gchandle_new allows you to pin when creating the handle, but is it possible to pin after the fact?

like image 157
Jeff Avatar answered Nov 15 '22 00:11

Jeff