[Mono-list] How to pass an object as ref or out

Robert Jordan robertj at gmx.net
Thu Apr 17 14:41:24 UTC 2014


On 17.04.2014 06:26, carmack2000 wrote:
> Hi Robert,
> Thanks for your tips but I still don't understand how to unbox a ref-type.
> It looks mono_object_unbox only can handle valuetype, not ref-type.
>
> So could you please write more lines of code of implementation for an
> example for this void SetPosition(MonoString* ms, MonoObject** mo) ?

Well, I need more info to be able to do this. Right now,
you're declaring a managed "ref object" argument on your
InternalCall. This forces boxing on every value type
passed as an argument.

The naive implementation would look like this:

void SetPosition(MonoString* ms, MonoObject** mo)
{
	Vector2 pos = *(Vector2*)mono_object_unbox(*mo);
}

This is no better than the former non-ref version.

Robert




More information about the Mono-list mailing list