Youssef Shoaib [MOD]11/14/2023, 7:24 PM
? Or is that close enough in performance to a List, and so a List makes more sense because of ergonomics? In other words, I'm creating a List of exactly size N, but I'm adding the elements recursively, and so I'm not really building them based on the index. Is an Array + lastIndex "better" in any way, or is a List with initial capacity close enough in performance
data class AppendableArray<T>(array: Array<T>, freeIndex: Int)
Joffrey11/14/2023, 7:26 PM
Youssef Shoaib [MOD]11/14/2023, 7:28 PM
Joffrey11/14/2023, 7:34 PM
is technically a wrapper over an array+index, that replaces the array with a bigger one when needed. If you tune the initial capacity so it never resizes the array, I don't believe there should be a significant performance difference when writing data. There could be some subtleties related to indirections of using the list wrapper to edit the array (e.g. memory locality), but I'm not sure this would have a noticeable impact on perf (also if you write your own wrapper, you have the same problem). One big difference of course would be using
, but that only applies to primitives.
Youssef Shoaib [MOD]11/14/2023, 7:38 PM
would matter too much. This was a purely academic exercise, so my question is entirely theoretical.
Array<IntArray> + some mutable index
ephemient11/14/2023, 7:39 PM
from its superclass
is basically an alias on JVM
Joffrey11/14/2023, 7:45 PM
I was wondering if having an ArrayList<IntArray> Vs Array<IntArray> + some mutable index would matter too muchIf you compare
to your wrapper class (and not to the direct usage of the array itself), then it's pretty much the same
Klitos Kyriacou11/15/2023, 9:06 AM
it would check its capacity, which your custom class wouldn't do because it already knows it has the capacity. But I don't think you'd be able to measure that difference.