We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
本文为读 lodash 源码的第一百八十五篇,后续文章会更新到这个仓库中,欢迎 star:pocket-lodash
gitbook也会同步仓库的更新,gitbook地址:pocket-lodash
import cloneArrayBuffer from './cloneArrayBuffer.js'
《lodash源码分析之cloneArrayBuffer》
cloneDataView 的作用是用来复制 dataView 视图。
cloneDataView
dataView
源码如下:
function cloneDataView(dataView, isDeep) { const buffer = isDeep ? cloneArrayBuffer(dataView.buffer) : dataView.buffer return new dataView.constructor(buffer, dataView.byteOffset, dataView.byteLength) }
由于 dataView 只是 arrayBuffer 上的一种视图,如果不需要深度复制,则直接使用原来的内存 dataView.buffer ,在原来的内存上新建一个 dataView 视图即可。
arrayBuffer
dataView.buffer
如果需要深度复制,则调用 cloneArrayBuffer ,将原来的 buffer 复制到一块新的内存,再在这块内存上创建 dataView 视图。
cloneArrayBuffer
buffer
dataView 视图可能操作的不是整块内存,因此在构建新的 dataView 视图时,要传入 dataView.byteOffset 来指定和原来视图一样的开始位置。
dataView.byteOffset
署名-非商业性使用-禁止演绎 4.0 国际 (CC BY-NC-ND 4.0)
最后,所有文章都会同步发送到微信公众号上,欢迎关注,欢迎提意见:
作者:对角另一面
The text was updated successfully, but these errors were encountered:
No branches or pull requests
本文为读 lodash 源码的第一百八十五篇,后续文章会更新到这个仓库中,欢迎 star:pocket-lodash
gitbook也会同步仓库的更新,gitbook地址:pocket-lodash
依赖
《lodash源码分析之cloneArrayBuffer》
源码分析
cloneDataView
的作用是用来复制dataView
视图。源码如下:
由于
dataView
只是arrayBuffer
上的一种视图,如果不需要深度复制,则直接使用原来的内存dataView.buffer
,在原来的内存上新建一个dataView
视图即可。如果需要深度复制,则调用
cloneArrayBuffer
,将原来的buffer
复制到一块新的内存,再在这块内存上创建dataView
视图。dataView
视图可能操作的不是整块内存,因此在构建新的dataView
视图时,要传入dataView.byteOffset
来指定和原来视图一样的开始位置。License
署名-非商业性使用-禁止演绎 4.0 国际 (CC BY-NC-ND 4.0)
最后,所有文章都会同步发送到微信公众号上,欢迎关注,欢迎提意见:
作者:对角另一面
The text was updated successfully, but these errors were encountered: