mbed Region m_data_2溢出堆栈和堆

时间:2017-03-29 11:32:06

标签: arm rtos mbed

我正在编写一个可在K64F主板上运行的Mbed OS应用程序。我使用系统的RTOS功能运行不同的线程。

我需要处理一个相对较大的字符串,以便以JSON格式显示结果。我把它定义为char数组。最初它被定义为256个字符长,并且工作正确,但是当我将大小增加到2048以实际满足应用程序的需求时

char rData[2048];

我在编译时收到此错误:

c:/program files (x86)/gnu tools arm embedded/6.2 2016q4/bin/../lib/gcc/arm-none-eabi/6.2.1/../../../../arm-none-eabi/bin/ld.exe: ./BUILD/K64F/GCC_ARM/02_device.elf section `.heap' will not fit in region `m_data_2'
c:/program files (x86)/gnu tools arm embedded/6.2 2016q4/bin/../lib/gcc/arm-none-eabi/6.2.1/../../../../arm-none-eabi/bin/ld.exe: Region m_data_2 overflowed with stack and heap
c:/program files (x86)/gnu tools arm embedded/6.2 2016q4/bin/../lib/gcc/arm-none-eabi/6.2.1/../../../../arm-none-eabi/bin/ld.exe: region `m_data_2' overflowed by 22944 bytes
collect2.exe: error: ld returned 1 exit status
[ERROR] c:/program files (x86)/gnu tools arm embedded/6.2 2016q4/bin/../lib/gcc/arm-none-eabi/6.2.1/../../../../arm-none-eabi/bin/ld.exe: ./BUILD/K64F/GCC_ARM/02_device.elf section `.heap' will not fit in region `m_data_2'
c:/program files (x86)/gnu tools arm embedded/6.2 2016q4/bin/../lib/gcc/arm-none-eabi/6.2.1/../../../../arm-none-eabi/bin/ld.exe: Region m_data_2 overflowed with stack and heap
c:/program files (x86)/gnu tools arm embedded/6.2 2016q4/bin/../lib/gcc/arm-none-eabi/6.2.1/../../../../arm-none-eabi/bin/ld.exe: region `m_data_2' overflowed by 22944 bytes
collect2.exe: error: ld returned 1 exit status

我没有找到任何关于如何增加为此需求保留的空间的参考。

我错过了什么?

1 个答案:

答案 0 :(得分:1)

在堆上声明变量,而不是在堆栈上声明:

char* rData = (char*)malloc(2048);
// potentially, don't always malloc 2048 bytes, but only the amount you need

完成后不要忘记致电free(rData)

相关问题