Open jkthorne opened 5 years ago
I think there should be an API for resizing an array. This is useful when you know you are about to insert a large amount of data and you only want one allocation of memory and one memory copy.
This is a followup from a conversation on the array buffer refactor. https://github.com/crystal-lang/crystal/pull/8166#issuecomment-534233809
Pros: Gives more flexibility in memory allocations and the potential for performance.
Cons: More APIs to support and is a more advanced feature.
So you don't know the size when you first create it, I presume? Maybe make resize_to_capacity public?
Note: This is already addressed in #11485 (Array#ensure_capacity).
Array#ensure_capacity
I think there should be an API for resizing an array. This is useful when you know you are about to insert a large amount of data and you only want one allocation of memory and one memory copy.
This is a followup from a conversation on the array buffer refactor. https://github.com/crystal-lang/crystal/pull/8166#issuecomment-534233809
Pros: Gives more flexibility in memory allocations and the potential for performance.
Cons: More APIs to support and is a more advanced feature.