How to display a dynamically allocated array in the Visual Studio debugger?

Solution 1:

Yes, simple. say you have

char *a = new char[10];

writing in the debugger:

a,10

would show you the content as if it were an array.

Solution 2:

There are two methods to view data in an array m4x4:

float m4x4[16]={
    1.f,0.f,0.f,0.f,
    0.f,2.f,0.f,0.f,
    0.f,0.f,3.f,0.f,
    0.f,0.f,0.f,4.f
};

One way is with a Watch window (Debug/Windows/Watch). Add watch =

m4x4,16

This displays data in a list:

enter image description here

Another way is with a Memory window (Debug/Windows/Memory). Specify a memory start address =

m4x4

This displays data in a table, which is better for two and three dimensional matrices:

enter image description here

Right-click on the Memory window to determine how the binary data is visualized. Choices are limited to integers, floats and some text encodings.

Solution 3:

In a watch window, add a comma after the name of the array, and the amount of items you want to be displayed.

Solution 4:

a revisit:

let's assume you have a below pointer:

double ** a; // assume 5*10

then you can write below in Visual Studio debug watch:

(double(*)[10]) a[0],5

which will cast it into an array like below, and you can view all contents in one go.

double[5][10] a;