TLDR: Support in the multi_heap component for realloc().
Problem description
Currently there is no way to perform an implicit vector.resize() operation over a multi_heap allocator for example. The user/lib will have to explicitly free, and alloc (even if the chunk itself was large enough for the desired resize()/reserve().
Proposed change
Add support both for sys_multi_heap_realloc and sys_multi_heap_aligned_realloc (similarly to sys_heap):
Note: Over this can add support as well for shared_multi_heap as a wrapper for the proposed new multi_heap functionality.
Note: See man 3 realloc for the special cases.
Detailed RFC
sys_multi_heap_realloc will perform the following (simple flow outlined):
Find relevant heap of allocated ptr
Retrieve usable size of ptr
If requested size is larger than usable size, allocate on multiheap (new alloc can reside on different pool)
memcpy(new_ptr, ptr, size);
Other flows:
If requested size is smaller than usable size, return ptr
If failed to allocate new_ptr return NULL
Note: Important to deal with the "special" realloc cases (!ptr, !size, ...)
Proposed change (Detailed)
Dependencies
Concerns and Unresolved Questions
Do we need to free the original ptr upon failure to allocate new buffer ?
This is an implementation detail in realloc, and not a MUST.
Introduction
TLDR: Support in the
multi_heap
component forrealloc()
.Problem description
Currently there is no way to perform an implicit
vector.resize()
operation over amulti_heap
allocator for example. The user/lib will have to explicitly free, and alloc (even if the chunk itself was large enough for the desiredresize()
/reserve()
.Proposed change
Add support both for
sys_multi_heap_realloc
andsys_multi_heap_aligned_realloc
(similarly tosys_heap
):Note: Over this can add support as well for
shared_multi_heap
as a wrapper for the proposed newmulti_heap
functionality. Note: Seeman 3 realloc
for the special cases.Detailed RFC
sys_multi_heap_realloc
will perform the following (simple flow outlined):ptr
ptr
size
is larger than usable size, allocate on multiheap (new alloc can reside on different pool)memcpy(new_ptr, ptr, size);
Other flows:
If requested
size
is smaller than usable size, returnptr
If failed to allocate
new_ptr
returnNULL
Note: Important to deal with the "special"
realloc
cases (!ptr
,!size
, ...)Proposed change (Detailed)
Dependencies
Concerns and Unresolved Questions
Do we need to free the original
ptr
upon failure to allocate new buffer ? This is an implementation detail in realloc, and not a MUST.Alternatives
N/A