ap_copy_array_hdr — create a copy of an array with copy-on-write
array_header *ap_copy_array_hdr(pool *p, const array_header *arr)
Copies the array arr
into the pool
p
without immediately copying the
array’s storage. If the array is extended with
push_array
, the original array is copied to the
new array before the extension takes place. Returns a pointer to the
new array.
There are at least two pitfalls with this function. First, if the array is not extended, its memory is destroyed when the original array is destroyed; second, any changes made to the original array may also affect the new array if they occur before the new array is extended.