locked
Detecting Boxing and Unboxing RRS feed

Answers

  • That content is from 2004, and quite out of date.  Since that was from .NET 1.1 days - you can just as easily approach this in .NET 2+ projects using a much easier approach.  Instead of looking for box/unbox operations, just look for collections using System.Collections.  I'd start by  searching for "using System.Collections;" and remove all usings, then migrate the corresponding code to the equivalent collection in System.Collections.Generics.  Boxing overhead is worst when dealing with loops, which tends to be dealing with collections, and moving to the generic versions will take care of 95%+ of what the IL approach would have found.

     

    However - Personally, I would approach performance tuning a bit differently.  If you're worried about optimizations, I would run your code through a good performance profiler, and use that to determine problematic regions of code.  This will be far more effective than trying to find specific optimizations, as it will show you real issues in your real code.

     

     

     


    Reed Copsey, Jr. - http://reedcopsey.com
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    • Proposed as answer by Shane_B Friday, April 1, 2011 1:24 AM
    • Marked as answer by Paul Zhou Friday, April 8, 2011 2:38 AM
    Friday, April 1, 2011 12:28 AM