登录
首页 >  Golang >  Go问答

runtime.memclrNoHeapPointers 的功能是什么?

来源:stackoverflow

时间:2024-03-23 23:45:34 181浏览 收藏

runtime.memclrNoHeapPointers 函数用于清除一段内存区域,该区域不包含指向堆的指针。它通常用于清除已初始化的无指针类型内存或未初始化的内存(例如,正在重用的新分配内存)。该函数是垃圾收集器的一部分,其具体功能取决于 CPU。

问题内容

我正在分析一个库,发现一个名为 runtime.memclrnoheappointers 的函数占用了大约 0.82 秒的 cpu 时间。

这个函数有什么作用,它告诉我有关我正在分析的库的内存使用情况的什么信息?

为了完整性,输出:

File: gribtest.test
Type: cpu
Time: Feb 12, 2019 at 8:27pm (CET)
Duration: 5.21s, Total samples = 5.11s (98.15%)
Showing nodes accounting for 4.94s, 96.67% of 5.11s total
Dropped 61 nodes (cum <= 0.03s)
      flat  flat%   sum%        cum   cum%
     1.60s 31.31% 31.31%      1.81s 35.42%  github.com/nilsmagnus/grib/griblib.(*BitReader).readBit
     1.08s 21.14% 52.45%      2.89s 56.56%  github.com/nilsmagnus/grib/griblib.(*BitReader).readUint
     0.37s  7.24% 59.69%      0.82s 16.05%  encoding/binary.(*decoder).value
     0.35s  6.85% 66.54%      0.35s  6.85%  runtime.memclrNoHeapPointers

解决方案


func memclrNoHeapPointers(ptr unsafe.Pointer, n uintptr)

memclrNoHeapPointers 清除从 ptr 开始的 n 个字节。

通常您应该使用 typedmemclr。 memclrNoHeapPointers 应该是 仅当调用者知道 *ptr 不包含堆指针时使用 因为:

  1. *ptr 是已初始化的内存,其类型是无指针的。

  2. *ptr 是未初始化的内存(例如,正在重用的内存

用于新分配),因此仅包含“垃圾”。

在 memclr_*.s 中 go:noescape

参见https://github.com/golang/go/blob/9e277f7d554455e16ba3762541c53e9bfc1d8188/src/runtime/stubs.go#L78

这是垃圾收集器的一部分。 You can see the declaration here.

它的具体功能取决于 CPU。 See the various memclr_*.s files in the runtime for implmentation

这在 GC 中看起来确实很长一段时间,但我认为仅凭您显示的数据很难说明库的内存使用情况。

今天带大家了解了的相关知识,希望对你有所帮助;关于Golang的技术知识我们会一点点深入介绍,欢迎大家关注golang学习网公众号,一起学习编程~

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>