Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vs2010 c++ view pointers content by debug

I'm working in Vs2010 c++ with 2D arrays. I started off with a 1D pointer and used the operation [] as the following:

class CMatrix
{
    void clear();
public:
    int nRows;
    int nCols;
    short * MyMat;

    CMatrix();
    CMatrix(int r,int c);
    ~CMatrix(void);

    void SetMatrix(int r,int c);
    short * operator[] (const int row)
    {
        return MyMat + (row*nCols);
    }
};

I don't mind to change to 2D pointer.

However my problem is with debug. Because I'm using pointers I can't see the arrays content.

Are there any another options ?

I prefer not to use vector.

like image 865
Ami DATA Avatar asked Nov 28 '22 16:11

Ami DATA


1 Answers

One way is to use use the Memory viewer. While debugging ( when stoped at a Breakpoint ), goto the menu Debug > Windows > Memory > Memory 1 to get the memory viewer. Then type-in the memory address ( copy paste the value from your pointer ) so that you can view the memory around that area of your program memory.

When you right click on memory viewer you can choose how you want to view the data ( as ANSI , as 4 integers, as 2 byte integers , as floats , bla bla... )

Also you can use the Watch window at the debug time. just use your pointer as an array ( e.g. if your pointer is char * t, the syntax t[0] will give your data pointed by the pointer t

like image 184
Deamonpog Avatar answered Dec 01 '22 06:12

Deamonpog