Friday, August 21, 2009

Visual Studio Watch Window Tip #1

A very usefull debugging tip that I use a lot is the ability to watch dynamically allocated arrays. Look at the code above. An array is allocated dynamically and the debugger most often can't display the content of the array in the "watch window" since it often can't determine the size of the array. The array in the watch window will look like this:

The debugger shows only the first entry in the array. Usually when you want to watch a dynamically allocated array you "kind of" know it's size. In the above example I know the size of the array is 10. I can simply tell Visual Studio how many elements to display to get a proper view of the content of the array like this:

All you do is add the size of the array after the variable name, separated by a comma ",". Now you can watch the contents of any array.

No comments:

Post a Comment