ucx
ucx copied to clipboard
UCS/DATASTRUCT: disable memcopy when passing _old_buffer_p to array_grow
What
Skip calling memcpy when passing _old_buffer_p to ucs_array_append_safe / ucs_array_reserve_safe, making it callers responsibility copying the data to the new allocated buffer.
Why ?
Some arrays may contain pointers or pointer-based data structures (e.g. linked lists), for which amemcpy won't do, and the inner data structures would break.
General comment. I understand the importance of this fix, but it still looks a bit strange to me, because of 2 things:
- IMO it is still error prone to leave the copy part to the caller. It means that other existing API functions would never work properly: ucs_array_append, ucs_array_resize. If you go this way, then maybe during array initialization we may keep a function pointer to the array-resize. Then it will be called automatically each time array is re-allocated with the new address Still this is not what I would propose..
- If someone has a collection of objects of complex type, then the obvious choices are:
- just store array of pointers, not objects, so that objects content is never copied
- store them in the linked list Because it looks like the wrong data structure choice, if you need to copy the whole content of the vector
Per discussion with @roiedanino and @iyastreb , we'll only support "trivial" types without custom user copy ctor + need to add a comment in docs.