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!