Creating array using emx array api with initialization to zero
이전 댓글 표시
I have MATLAB Coder project which contains emx arrays.
When I generate C code in MATLAB R2021a, Coder generates emxCreate function with calloc inside:
emxArray_Nodes *emxCreateND_Nodes(int numDimensions, const int *size)
{
emxArray_Nodes *emx;
int numEl;
emxInit_Nodes(&emx, numDimensions);
numEl = 1;
for (int i = 0; i < numDimensions; i++) {
numEl *= size[i];
emx->size[i] = size[i];
}
emx->data = (Nodes *)calloc(static_cast<unsigned int>(numEl), sizeof(Nodes));
emx->numDimensions = numDimensions;
emx->allocatedSize = numEl;
return emx;
}
But when I generate C code in MATLAB R2023b, Coder generates emxCreate funciotn with malloc:
emxArray_Nodes *emxCreateND_Nodes(int numDimensions, const int *size)
{
emxArray_Nodes *emx;
int numEl;
emxInit_Nodes(&emx, numDimensions);
numEl = 1;
for (int i = 0; i < numDimensions; i++) {
numEl *= size[i];
emx->size[i] = size[i];
}
emx->data = static_cast<Nodes *>(
malloc(static_cast<unsigned int>(numEl) * sizeof(Nodes)));
emx->numDimensions = numDimensions;
emx->allocatedSize = numEl;
return emx;
}
In the second code memory for my struct arrays is allocated without initialization to zero. As a result, after updating MATLAB, code behaviour was changed.
How can I force MATLAB Coder R2023b to generate emx Create functions with calloc inside for initialization all struct array elements with zeros?
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Simulink Coder에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!