github.com/primecitizens/pcz/std@v0.2.1/core/mem/clear.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright 2023 The Prime Citizens 3 4 //go:build pcz 5 6 package mem 7 8 import ( 9 "unsafe" 10 ) 11 12 // Clear clears n bytes starting at ptr. 13 // 14 // Usually you should use TypedClear. Clear should be 15 // used only when the caller knows that *ptr contains no heap pointers 16 // because either: 17 // 18 // *ptr is initialized memory and its type is pointer-free, or 19 // 20 // *ptr is uninitialized memory (e.g., memory that's being reused 21 // for a new allocation) and hence contains only "junk". 22 // 23 // Clear ensures that if ptr is pointer-aligned, and n 24 // is a multiple of the pointer size, then any pointer-aligned, 25 // pointer-sized portion is cleared atomically. Despite the function 26 // name, this is necessary because this function is the underlying 27 // implementation of TypedClear and memclrHasPointers. See the doc of 28 // memmove for more details. 29 // 30 // The (CPU-specific) implementations of this function are in memclr_*.s. 31 // 32 // See ${GOROOT}/src/runtime/stubs.go#func:memclrNoHeapPointers 33 // 34 //go:noescape 35 func Clear(ptr unsafe.Pointer, n uintptr)