[Mono-devel-list] Performance w/ boxing

Jonathan Pryor jonpryor at vt.edu
Sat Feb 21 07:57:00 EST 2004


On Sat, 2004-02-21 at 10:10, Jonathan Gilbert wrote:
> We are talking at different reference levels here :-) 

That's the problem with language.  Even when you're trying to be
explicit, you can still misunderstand others. :-)


> Well, that, or explicit boxing as I mentioned. The design that I presented
> was aimed to solve the "can be null" problem, and you no doubt read Joshua
> Tauberer's post which further addresses the performance issue.

Now that you provide that description, you remind me of the
System.Data.SqlTypes structures, which wrap a value, and provide a way
of asking whether it's "null" or not:

	void function (SqlInt32 n)
		if (n.IsNull) {/* ... */}
		else {/* compute something with n.Value */}

	void Test ()
		function (new SqlInt32());	// IsNull == true
		function (new SqlInt32(42));	// IsNull == false

> Joshua Tauberer's struct, being a value type, is effectively no different
> from using a separate 'bool' parameter to indicate whether the variable is
> present, except that it wraps it up nicely into a single parameter.

And conveniently enough, this construct is already in .NET.  Wish I'd
remembered this before.


Of course, in the future we'll have a generics-based equivalent,
Nullable<T> or something, which provides the same functionality.

 - Jon

More information about the Mono-devel-list mailing list