statmark5611/10/2023, 3:25 PM
If I create a list via:
val map: Map<Int, String> = ...
Will I cause memory allocation: 2*N, where N = size of String entries (1 from map, 1 from the list)?
val list: List<String> = map.values.toList()
Jacob11/10/2023, 3:49 PM
Klitos Kyriacou11/10/2023, 4:03 PM
is a collection. There's no technical reason
couldn't exist for a collection, but it doesn't. It's only defined for arrays.
Johann Pardanaud11/10/2023, 4:04 PM
Klitos Kyriacou11/10/2023, 4:06 PM
is a Collection, which is already an
. The main point for the OP is don't call
unless you absolutely need a
Johann Pardanaud11/10/2023, 4:08 PM
statmark5611/10/2023, 4:13 PM
Wout Werkman11/10/2023, 4:19 PM
will most likely be implemented as a view. So it will most likely have allocations independent of
will always introduce at least
, and most likely not more
Jacob11/10/2023, 4:20 PM
ephemient11/10/2023, 4:51 PM
ilya.gorbunov11/12/2023, 12:41 AM
That could be nice, but map.values is a collection. There's no technical reason@Klitos Kyriacou For example, one reason is thatcouldn't exist for a collection,
requires implementing indexed access to elements and reverse iteration and
doesn't provide these.
Klitos Kyriacou11/12/2023, 3:03 PM