[Mono-list] Code optimizations

Yoav HaCohen yoavhacohen at gmail.com
Sat Feb 21 13:16:57 EST 2009

Robert Jordan wrote:
> Yoav HaCohen wrote:
>> Here is my first idea:
>> Suppose we have the following code:
>> [DllImport(NATIVE_LIBRARY, CallingConvention = CallingConvention.Cdecl)]
>>         private static extern void NativeFoo(int temp, out int cx, out
>> int
>> cy);
>> public System.Drawing.Point Foo()
>> {
>> 	int cx, cy;
>> 	NativeFoo(int a, out cx, out cy);
>> 	return new System.Drawing.Point(cx, cy);
>> |
> I'm aware that you did not intend to start a discussion
> about p/invoke, but I could not resist (1):
> You don't want to p/invoke just to get one point out of
> the unmanaged world. The managed/unmanaged transition
> is too costly for this. Any optimization done by the JIT
> after this call would be pointless.
> When dealing with (arrays of) Point/Rectangle/Size (and other similar
> well known structs), there is a (rather dirty) way to gain speed:
> Define Point/Rectangle/Size as structs in the unmanaged
> world and pass them by reference back and forth.
> Robert
> (1) that's why designers are using "lorem ipsum" paragraphs for
> prototyping ;)
> _______________________________________________
> Mono-list maillist  -  Mono-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list

I know that it's costly to call unmanaged from managed code but there are a
good reason in this case for doing that.

Anyway, this is just an example, such cases can be also found in the managed

My philosophy is that there is no "pointless" optimization if nothing is
required from the developer.

View this message in context: http://www.nabble.com/Code-optimizations-tp22119164p22138683.html
Sent from the Mono - General mailing list archive at Nabble.com.

More information about the Mono-list mailing list