From 095312fa3f554d5806cb97a3ba7069335e640c2d Mon Sep 17 00:00:00 2001 From: Damian Gryski Date: Wed, 2 Mar 2022 12:44:04 -0800 Subject: [PATCH] src/syscall: document Environ() single-allocation tradeoff --- src/syscall/syscall_libc.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/syscall/syscall_libc.go b/src/syscall/syscall_libc.go index 0ef64984..fd94d893 100644 --- a/src/syscall/syscall_libc.go +++ b/src/syscall/syscall_libc.go @@ -235,6 +235,14 @@ func Mprotect(b []byte, prot int) (err error) { } func Environ() []string { + + // This function combines all the environment into a single allocation. + // While this optimizes for memory usage and garbage collector + // overhead, it does run the risk of potentially pinning a "large" + // allocation if a user holds onto a single environment variable or + // value. Having each variable be its own allocation would make the + // trade-off in the other direction. + // calculate total memory required var length uintptr var vars int