Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Tool to detect boxing/unboxing?

Tool to detect boxing/unboxing?

Scheduled Pinned Locked Moved C#
performancequestioncode-review
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    LiamD
    wrote on last edited by
    #1

    Does anyone know of a tool (preferably free) to determine the location of boxing/unboxing within a project. The aim is to improve performance and justify all boxing operations. Thanks LiamD

    H 1 Reply Last reply
    0
    • L LiamD

      Does anyone know of a tool (preferably free) to determine the location of boxing/unboxing within a project. The aim is to improve performance and justify all boxing operations. Thanks LiamD

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      You could use ildasm.exe from the .NET Framework SDK to disassemble the assembly to IL and search for "box" and "unbox". But if you're aim is to determine how ths impacts performance you should use a code profiler. There are many already available for the .NET Framework - both free and commercial - and they aren't too terribly difficult to write if you'd rather do that. The CLR Profiler for the .NET Framework 2.0[^] is one developed at Microsoft and is used in a lot of MSDN articles as wellas in blogs like Rico Mariani's[^], who's responsible for performance in the Developer Division. Not only will it help you determine where boxing is performed but also how often and how much impact is has on your application's performance. Also remember that any time you treat a number, struct, or enumeration as a reference type (anything that derives from System.ValueType) boxing will occur. This is one of many great reasons for generics (similar to C++ templates) in the .NET Framework, so that you can avoid boxing like so:

      // Boxing
      ArrayList list = new ArrayList();
      list.Add(1);
      list.Add(2);
      list.Add(3);
       
      // No boxing
      List<int> list = new List<int>();
      list.Add(1);
      list.Add(2);
      list.Add(3);

      This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Customer Product-lifecycle Experience Microsoft [My Articles] [My Blog]

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups