MCU上的Matlab代码生成和malloc [英] Matlab code generation and malloc on MCU

查看:321
本文介绍了MCU上的Matlab代码生成和malloc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友,



我不知道那种情况。

我有类似的代码。就像你看到这些代码包括malloc和calloc,我永远不会在MCU中使用free(),在这种情况下可以在我的项目中使用这些代码吗?



我试过的:



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;
  }
}

推荐答案

你不应该使用你不明白的代码。



这就是你向你的系统引入恶意软件的方式。
You should not use code you "do not understand".

That is how you introduce malware to your system.


这篇关于MCU上的Matlab代码生成和malloc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆