runtime.memclrNoHeapPointers 是做什么的?

What does runtime.memclrNoHeapPointers do?

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

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

完整的输出:

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 clears n bytes starting at ptr.

Usually you should use typedmemclr. memclrNoHeapPointers should be used only when the caller knows that *ptr contains no heap pointers because either:

  1. *ptr is initialized memory and its type is pointer-free.

  2. *ptr is uninitialized memory (e.g., memory that's being reused

for a new allocation) and hence contains only "junk".

in 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 中似乎花费了很长时间,但我认为仅凭您显示的数据很难说明库的内存使用情况。