gpt4 book ai didi

arrays - Kotlin toArray 与 asArray

转载 作者:行者123 更新时间:2023-12-02 12:44:08 25 4
gpt4 key购买 nike

只是想知道,Kotlin 库的 to- 和 as- 前缀有什么区别?

var buffer:ByteArray
// what's the difference between these two
buffer.toUByteArray()
buffer.asUByteArray()
我会想象一个引用数组的副本,另一个更像是指向内存中相同值的包装器,但我不确定。

最佳答案

toUByteArray:返回一个 UByteArray 类型的数组,它是这个数组的副本,其中每个元素都是这个数组对应元素的无符号重新解释。
asUByteArray:返回一个 UByteArray 类型的数组,它是这个数组的一个 View ,其中每个元素都是这个数组对应元素的无符号重新解释。
关于复制和 View 区别的说明:

While executing the functions, some of them return a copy of the input array, while some return the view. When the contents are physically stored in another location, it is called Copy. If on the other hand, a different view of the same memory content is provided, we call it as View


引用:
toUByteArray
asUByteArray
NumPy - Copies & Views

关于arrays - Kotlin toArray 与 asArray,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64054037/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com