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.

DM8148上的可变长度的数组?



我的平台是DM8148,现在有个压缩算法,在windows下运行是完全OK的,但移植到DSP下,遇到内存问题,下面我大概说下问题结构:

大概有结构如下

typedef struct _COMPRESSED_DATA_
{
  int width;

 int height;

 BYTE  m_Data[0];      // 压缩后数据
}COMPRESSEDDATA,PCOMPRESSEDDATA;

 

移植到CCS上编译,BYTE  m_Data[0]报错; 

我改成BYTE  *m_Data; 编译通过,运行用监视器发现m_Data的地址显示

“cannot read memory at 0x00000001:memory is not present”

 

请问专家这个问题怎么解决啊?

DSP上怎么才能定义一个可变长度的数组?

  • 我觉得你这个写法不大好吧,我的想法是在结构体里面定义指针,然后动态分配内存,你觉得呢

  • 我现在就是用指针

    typedef struct _COMPRESSED_DATA_

    {

     int width;

    int height;

    BYTE*  m_Data;      // 压缩后数据

    }COMPRESSEDDATA,PCOMPRESSEDDATA;

    程序是另一个结构体里申明了这样一个对象

    typedef struct EncodeData

    {

     int width;

    int height;

    short* RBuffer;

    short* GBuffer;

    short* BBuffer;

    PCOMPRESSEDDATA pCompressData;

    }ENCODEDATA,*PENCODEDATA;

    然后我是用pEncodeData->pCompressData= (PCOMPRESSEDDATA )malloc(CompressSize);

    这条语句分配内存的,但没分配成功