微控制器在malloc失败

微控制器在malloc失败,第1张

概述我正在32位cortex m4微控制器上编写函数. 该函数必须能够乘以不同大小的矩阵,这是我无法预测的.所以我必须使用malloc …… 但我不明白为什么我的mc在执行以下行时总是进入默认处理程序中断: double *output2=NULL;output2 = malloc(3 *1* sizeof(double *)); 这个mc是不是能够处理这种类型的 *** 作? 虽然这在我的笔记本电脑上工作 我正在32位cortex m4微控制器上编写函数.
该函数必须能够乘以不同大小的矩阵,这是我无法预测的.所以我必须使用malloc ……

但我不明白为什么我的mc在执行以下行时总是进入默认处理程序中断:

double *output2=NulL;output2 = malloc(3 *1* sizeof(double *));

这个mc是不是能够处理这种类型的 *** 作?
虽然这在我的笔记本电脑上工作得很好!

**编辑*

这里有一些代码(仍然需要修改……):
好吧所有的malocs都失败了.我无法为“malloced”数组赋值.

int main (voID){    /*some stuff*/    float transFRotMatrix[3][3]={0}; //array gets modifIEd by other functions    float sunMeasurements[3][1] = {{1},{2},{3}}; //test values        multiplyMatrices( &transFRotMatrix[0][0],3,&sunMeasurements[0][0],1,*orbitalSunVector);    /*some stuff*/}voID multiplyMatrices(float *transposedMatrix,int height1,int wIDth1,float *iSunVector,int height2,int wIDth2,float *orbitalSunVector){    int y=0;    int x = 0;    int row=0;    int column =0;    int k=0;    int k2 = 0;    float result = 0;    int i=0;    int j=0;    int t=0;    float rotationMatrix[3][3]={0};    i=0;    k=0;    k2 = 0;    if(wIDth1 != height2)    {        printf("unmatching matrices,error.\n\n");        return;    }    float *output2;    output2 = malloc(3 *1* sizeof(float *)); //<-----ERROR    while(k<wIDth1) //aantal rijen 1ste matrix    {        for(j=0;j<height2;j++) //aantal rijen 2de matrix        {            result += (*((transposedMatrix+k*wIDth1)+j)) * (*((iSunVector+j*wIDth2)+k2));  //1ste var:aantal kolommen 2de matrix  --2de variabele na de plus = aantal kolommen 2de matrix            //printf("%f * %f\t + ",(*((transposedMatrix+k*wIDth1)+j)),(*((iSunVector+j*wIDth2)+k2)));        }        output2[k*3 +k2] = result;  //<-----FAILS HERE        k2++;        x++;        column++;        if(x==wIDth2)        {            k2=0;            x=0;            column=0;            row++;            y++;            k++;        }        result = 0;    }    for(i=0;i<height1;i++)    {        for(j=0;j<wIDth2;j++)        {             orbitalSunVector[j * height1 + i] = output2[i*3 +j];        }    }    free(output2);}
解决方法 malloc()在此代码的其他部分工作正常吗?在编写嵌入式设备时,堆可能没有正确初始化,或者已经为另一个自定义的malloc()函数初始化了. 总结

以上是内存溢出为你收集整理的微控制器在malloc失败全部内容,希望文章能够帮你解决微控制器在malloc失败所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/1239647.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-06
下一篇2022-06-06

发表评论

登录后才能评论

评论列表(0条)

    保存