Hello friends,
I wonder that situation.
I have some codes like that.Like you see these codes include malloc and calloc ,and I never will use free() in MCU ,in this case is it ok to use these code in my project?
What I have tried:
<pre>
for(int i=0;i<4096;i++)
{
m[i] = qSin(2*3.14*50*t) + sin(2*3.14*100*t) + 2*qrand()/(RAND_MAX);
t = t + ts;
}
emxArray_real_T *Mshifted,*f;
emxInit_real_T(&Mshifted, 2);
emxInit_real_T(&f, 2);
emxEnsureCapacity((emxArray__common *)Mshifted, 0, (int32_T)sizeof(real_T));
emxEnsureCapacity((emxArray__common *)f, 0, (int32_T)sizeof(real_T));
Func1(m,ts,df,Mshifted,f);
void emxInit_real_T(emxArray_real_T **pEmxArray, int numDimensions)
{
emxArray_real_T *emxArray;
int i;
*pEmxArray = (emxArray_real_T *)malloc(sizeof(emxArray_real_T));
emxArray = *pEmxArray;
emxArray->data = (double *)NULL;
emxArray->numDimensions = numDimensions;
emxArray->size = (int *)malloc((unsigned int)(sizeof(int) * numDimensions));
emxArray->allocatedSize = 0;
emxArray->canFreeData = true;
for (i = 0; i < numDimensions; i++) {
emxArray->size[i] = 0;
}
}
void emxEnsureCapacity(emxArray__common *emxArray, int oldNumel, int elementSize)
{
int newNumel;
int i;
void *newData;
newNumel = 1;
for (i = 0; i < emxArray->numDimensions; i++) {
newNumel *= emxArray->size[i];
}
if (newNumel > emxArray->allocatedSize) {
i = emxArray->allocatedSize;
if (i < 16) {
i = 16;
}
while (i < newNumel) {
i <<= 1;
}
newData = calloc((unsigned int)i, (unsigned int)elementSize);
if (emxArray->data != NULL) {
memcpy(newData, emxArray->data, (unsigned int)(elementSize * oldNumel));
if (emxArray->canFreeData) {
free(emxArray->data);
}
}
emxArray->data = newData;
emxArray->allocatedSize = i;
emxArray->canFreeData = true;
}
}