3 ms·
A lot of languages handle this idiom more gracefully. Actually they don't. You can not resize a (static) array. What you really want is a dynamic array, an arr
by danbruc 13y ago
A lot of languages handle this idiom more gracefully.
Actually they don't. You can not resize a (static) array. What you really want is a dynamic array, an array list or whatever you like to call it. In this case you can double the size of the underlying array when you have to reallocate it and get the amortized runtime down but at the price of using up to twice the memory you need.
Maybe array_append is to blame because its pure existence somewhat implies that you are working with array lists and not with arrays.
- drob 13y agoCorrect -- they handle the idiom more gracefully in the context of an array-backed list, not an array. I elided the two as postgres arrays don't quite fit cleanly into either. (For example, evaluating arr[i] is O(i) for postgres arrays of variable width types.)