When the QT pointers for memory, view the pointer value is equal to the problems QtCreater 0

ThinkPadT570, Windows10, QT5.12.2 (QtCreater4.8.2) : This system configuration
is misleading when debugging break point when using QtCreater, see the relevant pointer variable value, as follows:

short *n2 = new short[1024*1024*1024];
if(n2==0)
{
    qDebug()<<"s2 == 0";
}
memset((char*)n2,1,1024*1024*1024*sizeof(short));
short ntemp = n2[1024*1024*1024-1];

When playing at a breakpoint in the following this line,
Here Insert Picture Description
you can see the pointer n2 is 0, my first reaction was what the fuck! ? Memory application did not succeed! ?
Here Insert Picture Description
Do not worry, there is no memory application is successful, continue to go down to know, press F10 to continue single-step debug, it did not go into this branch n2 == 0, as shown below:
Here Insert Picture Description
That is, the value of the pointer is not equal to 0 n2 ! Why in to see the value of the window to see what would be 0? This time, we look at n2 [0] value, as shown below,
Here Insert Picture Description
equal to 0, so I guess the image above to see the value of n2 is actually the first element of n2 points in memory, in order to verify my guess, we continue to go down, the memory assigned to n2 points, as shown below:
Here Insert Picture Description
at this time, view the value of n2 and found it changed, as shown below:
Here Insert Picture Description
Let us look at n2 [0] value, as shown below:
Here Insert Picture Description
can see the value of n2 equals the value of the first element pointing n2, proved my guess - to see the actual value of the pointer value is not qtcreater pointer, but the first element of the pointer ! (Figure above 257 why the value of? Is because the assignment when each byte is set to 1, and each two bytes a short, so that after the assignment is completed, the value of each element of a short pointer memory should 257)

Guess you like

Origin blog.csdn.net/weixin_43935474/article/details/90199605