3 ms·
Do you mean pointers returned by getenv() ? Those could point to thread-local buffers that data gets copied into when getenv() is called.
by HarHarVeryFunny 2y ago
Do you mean pointers returned by getenv() ? Those could point to thread-local buffers that data gets copied into when getenv() is called.
- debugnik 2y agoOnly if we're willing to take for granted that a call to getenv invalidates the previous one. POSIX allows it, but I'm concerned about runtimes scheduling user tasks on the same thread. If current platforms are safely making a copy of getenv before allowing their scheduler to interrupt, then yes I'd be ok with your solution.
- HarHarVeryFunny 2y agoIf you wanted to avoid "only latest getenv pointer per thread is valid", then the thread local data structure could be a var-name-> buffer map rather than a single reused buffer. Worst case memory usage (all threads get all vars) is that you end up having a separate copy of the environment per thread, but it seems this is the best that can be done given the awful API.