Re: Boxing and Unboxing ??

Tech-Archive recommends: Fix windows errors by optimizing your registry



Peter Olcott wrote:

Well that's not too bad then. It would seem that good design might be able to
completely eliminate the boxing and unboxing overhead penalty.

Yup. Nobody I know with experience worries much about this.

Is it possible to pass data around as unboxed data?

Yes - declare your types rather than using 'object'.

Can I pass the address of a struct, so that a
class member can update this struct without boxing and unboxing?

You can, but in a strictly downwards (call stack) fashion, via the 'ref'
modifier on arguments. You can't safely store the address.

With unsafe code, you can use the '&' operator to get the address, and
basically write C code to manipulate the data. But that's unsafe code:
it's not verifiable, it won't work if the executable is run from a
network location, and almost certainly won't work if you're (e.g.)
writing an ASP.NET application for hosting on a server somewhere -
unless you control the server & permissions completely.

What is the best way to get one class to update the struct data of another
class?

By calling methods on the other class.

-- Barry

--
http://barrkel.blogspot.com/
.