-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[Feature] Support pvPortRealloc #1315 #1351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
770037a to
e8cdb15
Compare
|
AniruddhaKanhere
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @skb666,
Thank you for taking the time to contribute to the FreeRTOS-kernel.
I have some comments/questions about your PR. Can you please take a look and let me know what you think?
| #endif | ||
|
|
||
| #if ( ( configSUPPORT_HEAP_REALLOC > 0 ) && ( configSUPPORT_DYNAMIC_ALLOCATION != 1 ) ) | ||
| #error configSUPPORT_HEAP_REALLOC cannot be used without dynamic allocation, but configSUPPORT_HEAP_REALLOC is not set to 1. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| #error configSUPPORT_HEAP_REALLOC cannot be used without dynamic allocation, but configSUPPORT_HEAP_REALLOC is not set to 1. | |
| #error configSUPPORT_HEAP_REALLOC cannot be used without dynamic allocation, but configSUPPORT_DYNAMIC_ALLOCATION is not set to 1. |
| /* Handle NULL pointer case - equivalent to malloc */ | ||
| if( pv == NULL ) | ||
| { | ||
| return pvPortMalloc( xWantedSize ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To adhere to MISRA rule 15.5, FreeRTOS doesn't use multiple return statements in a single function.
We'd need to refactor this a bit to accommodate that.
| { | ||
| mtCOVERAGE_TEST_MARKER(); | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would there not be a 4th case?
----------------------------------------------------------------------------------------------
| \\\\ block full \\\\ | free block | Current block | \\\\\\ block full \\\\\\ |
----------------------------------------------------------------------------------------------free block is 200 bytes long, the current block is 300 bytes long, and we call pvRealloc with size 400. Ideally, it would fit by merging the current block with the free block and moving data forward.
But in the algorithm that you propose, we are ignoring that possibility altogether.
Let me know if I am missing something.
| } | ||
| else | ||
| { | ||
| return NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my comments in heap_4 about multiple return statements



Description
This PR introduces a new API
pvPortReallocto FreeRTOS, providing dynamic memory reallocation similar to the standard C library'srealloc. WithconfigSUPPORT_HEAP_REALLOCenabled, applications can now resize heap-allocated memory blocks at runtime, either shrinking, expanding in place, or reallocating with data migration when needed.Key Changes:
pvPortReallocAPI inportable/MemMang/heap_4.candheap_5.c.configSUPPORT_HEAP_REALLOC(default 0, must be 1 to enable realloc support).FreeRTOSConfig.hand checked for correct configuration use.malloc.free.Test Steps
configSUPPORT_HEAP_REALLOCand ensure dynamic allocation is also enabled.heap_4.corheap_5.c.pvPortReallocto:NULLas input.0.Checklist:
Related Issue
#1315
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.