How can I change maximum available heap size for a task in FreeRTOS?

前端 未结 2 490
名媛妹妹
名媛妹妹 2021-01-25 07:51

I\'m creating a list of elements inside a task in the following way:

        l = (dllist*)pvPortMalloc(sizeof(dllist));

dllist is 32 byte big.

2条回答
  •  伪装坚强ぢ
    2021-01-25 08:06

    For the standard allocators you will find a config option in FreeRTOSConfig.h .

    However: It is very well possible you run out of memory already, depending on the allocator used. IIRC there is one that does not free() any blocks (free() is just a dummy). So any block returned will be lost. This is still useful if you only allocate memory e.g. at startup, but then work with what you've got.

    Other allocators might just not merge adjacent blocks once returned, increasing fragmentation much faster than a full-grown allocator.

    Also, you might loose memory to fragmentation. Depending on your alloc/free pattern, you quickly might end up with a heap looking like swiss cheese: Many holes between allocated blocks. So while there is still enough free memory, no single block is big enough for the size required.

    If you only allocate blocks that size there, you might be better of using your own allocator or a pool (blocks of fixed size). Thaqt would be statically allocated (e.g. array) and chained as a linked list during startup. Alloc/free would then just be push/pop on a stack (or put/get on a queue). That would also be very fast and have complexity O(1) (interrupt-safe if properly written).

    Note that normal malloc()/free() are not interrupt-safe.

    Finally: Do not cast void *. (Well, that's actually what standard malloc() returns and I expect that FreeRTOS-variant does the same).

提交回复
热议问题