Creating array using emx array api with initialization to zero
Mostra commenti meno recenti
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?
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Simulink Coder in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!