茶亦爽 发表于 2013-8-4 14:50:25

freertos内存管理源文件heap_4.c

看见这里没有提到关于freertos内存管理中源文件更新问题,在此给出最新的范例源文件heap_4.c.有关说明:

heap_4.c

This scheme uses a first fit algorithm and, unlike scheme 2, does combine adjacent free memory blocks into a single large block (it does include a coalescence algorithm).
The total amount of available heap space is set by configTOTAL_HEAP_SIZE - which is defined in FreeRTOSConfig.h.

The xPortGetFreeHeapSize() API function returns the total amount of heap space that remains unallocated (allowing the configTOTAL_HEAP_SIZE setting to be optimised), but does not provided information on how the unallocated memory is fragmented into smaller blocks.

This implementation:

1.Can be used even when the application repeatedly deletes tasks, queues, semaphores, mutexes, etc..
2.Is much less likely than the heap_2 implementation to result in a heap space that is badly fragmented into multiple small blocks - even when the memory being allocated and freed is of random size.
3.Is not deterministic - but is much more efficient that most standard C library malloc implementations.

heap_4.c is particularly useful for applications that want to use the portable layer memory allocation schemes directly in the application code (rather than just indirectly by calling API functions that themselves call pvPortMalloc() and vPortFree()).

次说明与heap_2.c进行了比较,在很多情况下heap_4.c的优越性更大,不易产生内存碎片。
页: [1]
查看完整版本: freertos内存管理源文件heap_4.c