You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Current reallocation way unconditionally moves entire old allocation to new memory area if there's no room to grow in place.
Growing dynamic arrays seem a bit ineffective in this case, when element needs to be inserted or prepended, rather than appended.
One of following additional functions could be used when data movement needs to be performed in special way.
void*realloc_need_move (ptr, size);
/* Test if realloc requires data move due to lack of space to grow in place. * If size is smaller than actual allocation - return false unconditionally */void*realloc_try_inplace (ptr, size);
/* Try to realloc without data move. * Return NULL if can't realloc without data move. */void*realloc_or_malloc (ptr, size);
/* Almost like default realloc, but if data move is required, just do new malloc, * without data movement and deletion of old area. */void*realloc_with_offsets (ptr, size, offsets);
/* Like original realloc, but also add offsets. This should be move effective when reallocated data are moved. * shifts - array of two interleaved elements: offset, [pos, offset,...] * - positive offset shifts subsequent data towards end, resulting to gap * - negative offset does same shift but backward, overwriting previous elements * - zero offset terminates offsets list * Optimizations could be possible e.g., when one offset is followed by same offset in reverse direction. */
I know at least one real example, where add/remove of elements in dynamic array always done by manual malloc with special data move. Of course, it's not even tlsf user.
The text was updated successfully, but these errors were encountered:
nick87720z
changed the title
More effective reallocation API
[Feature request] More effective reallocation API
Jun 20, 2021
I'm not completely sure about wayt to specify shifts in last proposed function. First time I assumed shifts to be relative (positive adds gap, negative removes number of bytes), but it also could be absolute.
Btw, after talk in zynaddsubfx irc channel (also tlsf user), I found, that shift would be better term for such operation, than offset.
Current reallocation way unconditionally moves entire old allocation to new memory area if there's no room to grow in place.
Growing dynamic arrays seem a bit ineffective in this case, when element needs to be inserted or prepended, rather than appended.
One of following additional functions could be used when data movement needs to be performed in special way.
I know at least one real example, where add/remove of elements in dynamic array always done by manual malloc with special data move. Of course, it's not even tlsf user.
The text was updated successfully, but these errors were encountered: