Integrate the new heap implementation from InfiniTime #97
Conversation
8fa1597 to
7ccff91
Compare
| } | ||
|
|
||
| namespace { | ||
| std::map<void *, size_t> allocatedMemory; |
There was a problem hiding this comment.
do we actually need an ordered map? I think an unordered_map would do just fine and has better runtime for search of O(1) in the best case
see: https://stackoverflow.com/a/13799886
| std::map<void *, size_t> allocatedMemory; | |
| std::unordered_map<void *, size_t> allocatedMemory; |
There was a problem hiding this comment.
Yes, indeed, we don't need the map to be ordered!
| size_t currentSize = 0; | ||
| std::for_each(allocatedMemory.begin(), allocatedMemory.end(), [¤tSize](const std::pair<void*, size_t>& item){ | ||
| currentSize += item.second; | ||
| }); |
There was a problem hiding this comment.
Nice use of <algorithm>, but we can be even more explicit using std::accumulate from <numeric>
| size_t currentSize = 0; | |
| std::for_each(allocatedMemory.begin(), allocatedMemory.end(), [¤tSize](const std::pair<void*, size_t>& item){ | |
| currentSize += item.second; | |
| }); | |
| const size_t currentSize = std::accumulate( | |
| allocatedMemory.begin(), allocatedMemory.end(), 0, | |
| [](const size_t lhs, const std::pair<void*, size_t>& item){ | |
| return lhs + item.second; | |
| }); |
There was a problem hiding this comment.
Nice, it's even better with std::accumulate!
| void *instance = nullptr; | ||
| }; | ||
| void *instance; | ||
| }TaskHandle_t; |
There was a problem hiding this comment.
nitpick: space before name
| }TaskHandle_t; | |
| } TaskHandle_t; |
| //StackType_t *pxStackBase; /* Points to the lowest address of the task's stack area. */ | ||
| uint16_t usStackHighWaterMark; /* The minimum amount of stack space that has remained for the task since the task was created. The closer this value is to zero the closer the task has come to overflowing its stack. */ | ||
| }; | ||
| }TaskStatus_t; |
There was a problem hiding this comment.
nitpick: space before name
| }TaskStatus_t; | |
| } TaskStatus_t; |
| auto minimumEverFreeHeap = xPortGetMinimumEverFreeHeapSize(); | ||
| if (currentFreeHeap != lastFreeHeapSize) { |
There was a problem hiding this comment.
we can move the minimum value getter into the if block to only get that value when we really need it
| auto minimumEverFreeHeap = xPortGetMinimumEverFreeHeapSize(); | |
| if (currentFreeHeap != lastFreeHeapSize) { | |
| if (currentFreeHeap != lastFreeHeapSize) { | |
| auto minimumEverFreeHeap = xPortGetMinimumEverFreeHeapSize(); |
| struct TaskHandle_t { | ||
| void *thread_handle = nullptr; | ||
| typedef struct TaskHandle_t { | ||
| void *thread_handle; |
There was a problem hiding this comment.
can we still default initialize in C code? I actually don't know
| void *thread_handle; | |
| void *thread_handle = 0; |
There was a problem hiding this comment.
Mhm I don't think we can do that in C, but this file should be compiled by the C++ compiler so it should work, I guess (and it builds).
|
#define LV_MEM_CUSTOM_INCLUDE <FreeRTOS.h> /*Header for the dynamic memory function*/
#define LV_MEM_CUSTOM_ALLOC pvPortMalloc /*Wrapper to malloc*/
#define LV_MEM_CUSTOM_FREE vPortFree /*Wrapper to free*/otherwise this PR would be fine to merge as it still works with the current main branch without the memory allocation changes edit: nevermind, I just needed to properly recompile. Now changing memory is showing |
…InfiniTime#1709). Since FreeRTOS.h, portmacro_cmsis.h and task.h are now built in C (by lv_mem.c), I had to change some includes and declarations to make them compatible with a C compiler. Integrating the new memory management from InfiniTime in InfiniSim is not easy because InfiniSim does not include the whole FreeRTOS. Which means that, for example, pvPortMalloc() and vPortFree() are not accessible from InfiniSim. As a first step, I provided custom implementations for pvPortMalloc(), vPortFree() which are based on ... malloc(). These function keep track of the memory that is currently allocated so that xPortGetFreeHeapSize(), xPortGetMinimumEverFreeHeapSize() return something. Not that this implementation do not keep track of all the memory allocations done in InfiniTime. It can only "see" those done via pvPortMalloc(). It means that the available memory displayed by InfiniSim will probably be very optimistic.
6b3b4e7 to
d67a74d
Compare
|
@NeroBurner I agree with all your comments, and thanks for applying the changes in the code! I'll merge the branch in InfiniTime soon so we can merge this one in InfiniSim :) |
|
you're welcome. Always nice to see a project being used and improved 🥰 |
Integration of this PR from InfiniTime.
Since FreeRTOS.h, portmacro_cmsis.h and task.h are now built in C (by lv_mem.c), I had to change some includes and declarations to make them compatible with a C compiler.
Integrating the new memory management from InfiniTime in InfiniSim is not easy because InfiniSim does not include the whole FreeRTOS. Which means that, for example, pvPortMalloc() and vPortFree() are not accessible from InfiniSim. As a first step, I provided custom implementations for pvPortMalloc(), vPortFree() which are based on ... malloc(). These function keep track of the memory that is currently allocated so that xPortGetFreeHeapSize(), xPortGetMinimumEverFreeHeapSize() return something.
Not that this implementation do not keep track of all the memory allocations done in InfiniTime. It can only "see" those done via pvPortMalloc(). It means that the available memory displayed by InfiniSim will probably be very optimistic.