[Mono-devel-list] Performance w/ boxing

Jonathan Pryor jonpryor at vt.edu
Fri Feb 20 07:36:51 EST 2004


Below...

On Fri, 2004-02-20 at 02:51, Piers Haken wrote:
> Yeah, just use  
> 
> 	void function (ref int a) {}
> 
> You can pass references to unboxed ints, boxed ints, or fields, however you
> can't pass indexers or properties.

That's not quite what the original poster (Jaroslaw Kowalski) wanted. 
He wanted a way to check for either (a) null, or (b) a boxed integer.  A
"ref" or "out" integer can never be null.

There is no way, within current C#, to ask for a boxed integer.  CIL
permits it, but C# does not.

If you want to use Microsoft's Managed Extensions for C++, though, you
can do it.  The syntax is something like:

	void function (int __gc *value) {/* ... */}

Of course, using Managed Extensions for C++ limits portability to zero
(there isn't any), so that's probably not the best of all possible
ideas...

 - Jon

> -----Original Message-----
> From: mono-devel-list-admin at lists.ximian.com
> [mailto:mono-devel-list-admin at lists.ximian.com] On Behalf Of Jaroslaw
> Kowalski
> Sent: Thursday, February 19, 2004 11:40 PM
> To: Ben Maurer
> Cc: Mono Development
> Subject: Re: [Mono-devel-list] Performance w/ boxing
> 
> Thanks for your reply.
> 
> BTW. How can I use a class similar to "BoxedInt" that you've mentioned? Is
> it supported with C#? DO I have to use unsafe code for this?
> 
> One more concern:
> 
> Is it possible (perhaps at the IL level) to specify an argument type of
> "boxed int32" or something similar?
> 
> I want a function to be passed either an integer or NULL. I don't want to
> allow the string to be passed there and if I declare the formal parameter as
> "object" I have no control over what can be passed there.
> 
> Conceptually it would be something like:
> 
> void function(boxed int a)
> {
>     if (a == null)
>     {
>     }
>     else
>     {
>         int k = (int)a;
>     }
> }
> 
> function(3);       // works
> function(null);    // works
> function("aaa");   // fails
> 
> Jarek

<snip/>





More information about the Mono-devel-list mailing list