Background: I'm developing for the xbox and am at the optomising stage. I need to cut down on object allocations. One place to start is finding out where (un)boxing occurs.
I'm very new to IL (in that i've never looked at any!) and would like to avoid running DLLs through a dissassembler, hunting for the (un)box command then trying to work out what line of code it relates to.
Question: Are there any tools which will report this kind of thing (where (un)boxing occurs) for me?
EDIT: Made request below into its own question since it's fairly distinct from this one.
Many, many, bonus points for a way of tieing a GC heap dump back to lines of code where the object creations occured!!
Boxing In C#The process of converting a Value Type variable (char, int etc.) to a Reference Type variable (object) is called Boxing.
Boxing is the process of converting a value type to the type object or to any interface type implemented by this value type. When the common language runtime (CLR) boxes a value type, it wraps the value inside a System. Object instance and stores it on the managed heap. Unboxing extracts the value type from the object.
When a value type is converted to object type, it is called boxing.
Unboxing is the explicit conversion process. Here, the value stored on the stack copied to the object stored on the heap memory. Here, the object stored on the heap memory copied to the value stored on the stack . Example: // C# program to illustrate Boxing.
This MSDN Magazine article details how to create an FxCop (Code Analysis) rule that detects boxing and unboxing and can present violations as a warning. The article is a little on the old side, but you should be able to adapt it to your needs.
There is a tool called BoxCop which does exactly that.
It is not really useful when trying to integrate the checks for boxing/unboxing into the build process. For that you would need some rule for FxCop.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With