This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

C6678:malloc函数是否做字节对齐



请教大神:我在写函数时,矩阵的大小是函数形参,想要申请动态缓存作为动态数组,但是之后的很多向量运算都必须字节对齐才能够计算,如DSPF_sp_vecrecip函数,所以我想问一下:malloc函数在CCS编译器中是否自动做了字节对齐;malloc函数申请的动态数组是否可以使用类似_amem4、_amemd8等要求字节对齐的内联函数?

  • 没有自动做对齐,用memalign函数
    Ordinary dynamic memory allocation does not guarantee that the address of the buffer is aligned
    7.5.8.3 Dynamic Memory Allocation
    www.ti.com/.../spru187o.pdf
  • 你好,Shine Zhang
    我使用了memalign函数,在函数前面申请缓存作为动态数组,
    float *temp1 = (float*)memalign(8, sizeof(float) * N);
    这样的指针我连续申请了5个;我设置的-heap= 0x30F000,-stack = 0xa000;申请的缓存在函数最后释放,并且这个函数被循环调用。
    调用第一次还计算正确,但是第二次调用,申请缓存里面的值就出错了。
    我想问:是否释放memalign申请的缓存仍然用free()函数?
    使用memalign函数还有什么其他的注意事项?是否不能同时申请很多?手册里面介绍的很少。。。