Quick Explanation :
A dynamic array is a structure that is intended to possibly encounter a lot of element insertion/push requests.
For this kind of structures, it’s is algorithmically more efficient to manage a buffer whoe size is actually larger than the size of the dynamic array, because doing so, you won’t need to re-allocate/duplicate the whole array in a new buffer each time you insert/push a new element.
When you insert a new element that requires a reallocation, the dynamic array actually allocates a bit more slots than necessary, so that further insertions/pushes do not cost much (by avoiding a complete buffer re-allocation each time). Inserting a new element at the end of the dynamic array becomes almost free (just write a value into an available memory slot and increment the dynamic array size counter).
And the more elements you have in your dynamic array, the more extra memory will be allocated when a re-allocation occurs (because if there are already as many elements in you da, G’MIC expect you potentially push as many more
).
In G’MIC, if you have a buffer size of N and you try to push M new elements at position N (so requiring a buffer reallocation), the new buffer size will be 2N + M.
So, to sum up, the dynamic array size and the buffer size are two different things:
- The dynamic array size is given by
da_size(#ind). - The buffer size is given by
h(#ind). da_size(#ind)<h(#ind), always!da_size(#ind)is atually the same asi[#ind,h(#ind) - 1].
Pro Tip: You should never use h(#ind) in your code if [ind] is a dynamic array, because it’s actually not an information you have to care about. It’s the role of the da_*() functions to deal with it, but definitely not yours.

















