- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
Dear all,
I have the following code:
...
node *node3=new node[npoint];
for (int i=0;i<npoint;i++)
{
node3.id=i;
node3.x=doublearray[j++];
node3.y=doublearray[j++];
node3.z=doublearray[j++];
}
std::qsort(node3,npoint,sizeof(node),comparenode);
...
The Intel Inspector tells me the 'Uninitialized memory access' error at line
node *node3=new node[npoint];
and qsort function.
How to understand this error? How to modify the code to remove this error message?
Thanks,
Zhanghong Tang
コピーされたリンク
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
>>>The Intel Inspector tells me the 'Uninitialized memory access' error at line>>>
Uninitialized memory access means that pointer which is supposed to contain the valid address was not initialized(does not contain valid address) probably null or some junk.
>>> node *node3=new node[npoint];>>>
Did actually try to run your code? Does it crash?
The quoted example while disassembled node3 pointer to array of objects type node should contain the address to heap allocated memory. The size of node array is the size of npoint elements multiplied by the object type node size.
Btw, that message could be also false positive for example when you earlier initialized *node3 pointer to null and Inspector was not able to track the changes(call to new operator).
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
Hi iliyapolak,
Thank you very much for your kindly reply. The code doesn't crash. I just use Intel Inspector to check possible hidden problems of my code.
Do you mean that I should initialize the pointer like this?
for (int i=0;i<npoint;i++)node3=0;
but I think the 'new' operation has assigned address for every node3.
I think I have assigned values for every node3 after the 'new' operation. On the other hand, if I have the following code after the 'new' operation, the error message disappeared.
memset(node3,0,npoint*sizeof(node));
but I don't think it is necessary since I have assigned values for every node3.
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
That is fine what you are doing . I also run strict rules code analysis from time to time.
I do not think that you need to initialize node array members to null. Operator new initialized *node3 pointer to point allocated heap memory.
IIRC at assembly level your objects are decomposed into primitive member variables (float,double) which are copied probably by vectorized mem copy function.
