[Mono-devel-list] Re: [Mono-hackers-list] Simple patch for the runtime

Paolo Molaro lupus at ximian.com
Tue Apr 8 05:36:32 EDT 2003


On 04/07/03 Lluis Sanchez wrote:
> > 3) I don't like much the fact that we enter unmanaged code to go back to
> > managed twice anyway. The icall could be:
> > ves_icall_System_AppDomain_InternalGetProcessGuid (MonoGuid *guid);
> > and
> > InternalGetProcessGuid (out Guid guid); in the C# side
> > so you can easily invoke at least the ToString() in C# code.
> 
> Hmm, this would make things more complex, unless I can safely use one Guid
> created in one domain in another domain. That's why I use an string, it is
> easy to make a copy of it for each domain.

A Guid is a struct with no domain-dependent fields, so, once created,
you just keep the Guid data, ie no object at all, and in the icall you
copy it to the passed-in pointer with a simple memcpy.
Or a better way may be to do this:
*) use a static string process_guid in AppDomain.cs.
*) if the string is non-null, return it
*) otherwise build a Guid and call ToString in it
*) pass this string to a icall like this:


// maybe this can be an array to avoid the need to malloc memory
// for it; need to adjust the check in the icall accordingly
static gunichar2 *process_guid = NULL;

MonoString * 
InternalGetProcessGuid (MonoString *newid) {

	lock ();
	if (process_guid) {
		unlock ();
		return mono_string_new_utf16 (process_guid, GUID_LEN);
	}
	copy from newid->chars to process_guid
	unlock ();
	return newid;
}

*) set the static field with the result of the InternalGetProcessGuid()
icall.

I think this would make the code cleaner, both in the C and the C# side
and there is no unnecessary managed<->unmanaged transitions.

lupus

-- 
-----------------------------------------------------------------
lupus at debian.org                                     debian/rules
lupus at ximian.com                             Monkeys do it better



More information about the Mono-devel-list mailing list