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.

[参考译文] RTOS/CC2650:动态分配

Guru**** 2595805 points


请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/processors-group/processors/f/processors-forum/580350/rtos-cc2650-dynamic-allocation

器件型号:CC2650

工具/软件:TI-RTOS

您好、

我真的不知道这是 C 问题还是 TI RTOS 问题。 (我不是 C 语言家庭)

我正在尝试从用户读取 UART 并放入一个数组。

当消息超过一定数量的字节时、我会分配更多字节(当然是动态的)

以下是我的代码:

System_printf ("任务1开始");\

UART_Handle 句柄;
UART_Params 参数;
//初始化 UART 并指定非默认参数
UART_PARAMS_INIT (params);
params.baudrate = 115200;
params.writeDataMode = UART_DATA_BINARY;
params.readDataMode = UART_DATA_BINARY;
//params.readCallback = readCallback;
//打开 UART 并启动第一次读取
句柄= UART_OPEN (Board_UART、params);
int bytesOfMessage = 10;
UChar*消息;
UChar* tempMessage;
Message = malloc (bytesOfMessage * sizeof (UChar));
int i = 0;
while (true)

int rxBytes = UART_Read (handle、rxBuf、1);

//System_printf ("%d \n"、rxBuf[0]);
if (rxBuf[0]!= 13)

message[i]= rxBuf[0];
i++;
int l = 1;

if (i ==字节 OfMessage)

System_printf ("第一条消息:\n");
for (l=0;<bytesOfMessage;l++)

//System_printf ("%c"、message[l]);

System_printf ("第一条消息的末尾"\n);

bytesOfMessage += 10;
//message = realloc (message、bytesOfMessage * sizeof (UChar));


tempMessage =(UChar*) realloc (message、bytesOfMessage * sizeof (UChar));
Message = tempMessage;
tempMessage =空;


System_printf ("Message2 %d:\n"、bytesOfMessage);
for (l=0;<bytesOfMessage;l++)

//System_printf ("%c"、message[l]);

System_printf ("第二条消息的末尾"\n);

UART_WRITE (handle、rxBuf、rxBytes);

其他

rxBuf[0]='\r\n';
rxBuf[1]='\n';
rxBuf[2]='n';
rxBuf[3]='e';
rxBuf[4]='w';
UART_WRITE (handle、rxBuf、5);

第一个 realloc 函数工作正常。  

第二个是卡滞。 我认为有足够的内存。

也许有人知道我为什么会发生这种情况?

体层器。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    Tomer、

    "拖"是什么意思?

    您可以为此项目共享.cfg 文件吗? 我想了解堆是如何配置的。

    您使用的是哪个版本的 TI-RTOS? CCSTM

    Alan
  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    由于原始海报中没有活动、我将关闭此项。

    Todd