我正在尝试使用 malloc() 函数为链表创建节点。在我的例子中,该函数在以下虚拟代码段上返回 NULL。
我在 atmega 2561 上运行 FREERTOS。
if (!malloc(sizeof(struct Event))
{
//The code gets inside here
} else {
//
}
节点的结构如下:
struct Event
{
uint8_t shouldCarBrake;
uint16_t tachoPoint;
struct Event *next;
};
最佳答案
如果项目设置为使用 FreeRTOS 随附的五个示例堆内存管理文件中的四个,则 C 库提供的堆大小可能为零。 5 个中只有 heap_3 使用 malloc。参见 http://www.freertos.org/a00111.html获取更多信息。
关于c - Malloc 无法在 atmega2561 和 freeRTOS 上分配内存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34168632/