mirror of
https://github.com/golang/go
synced 2024-11-19 02:04:42 -07:00
runtime: add comment
Explain why it's safe to allocate chans with flagNoScan. LGTM=rsc R=golang-codereviews CC=golang-codereviews, khr, rsc https://golang.org/cl/125510045
This commit is contained in:
parent
9601abaf8b
commit
4064d5e9a3
@ -33,7 +33,11 @@ func makechan(t *chantype, size int64) *hchan {
|
|||||||
|
|
||||||
var c *hchan
|
var c *hchan
|
||||||
if elem.kind&kindNoPointers != 0 || size == 0 {
|
if elem.kind&kindNoPointers != 0 || size == 0 {
|
||||||
// allocate memory in one call
|
// Allocate memory in one call.
|
||||||
|
// Hchan does not contain pointers interesting for GC in this case:
|
||||||
|
// buf points into the same allocation, elemtype is persistent
|
||||||
|
// and SudoG's are referenced from G so can't be collected.
|
||||||
|
// TODO(dvyukov,rlh): Rethink when collector can move allocated objects.
|
||||||
c = (*hchan)(gomallocgc(hchanSize+uintptr(size)*uintptr(elem.size), nil, flagNoScan))
|
c = (*hchan)(gomallocgc(hchanSize+uintptr(size)*uintptr(elem.size), nil, flagNoScan))
|
||||||
if size > 0 && elem.size != 0 {
|
if size > 0 && elem.size != 0 {
|
||||||
c.buf = (*uint8)(add(unsafe.Pointer(c), hchanSize))
|
c.buf = (*uint8)(add(unsafe.Pointer(c), hchanSize))
|
||||||
|
Loading…
Reference in New Issue
Block a user