在 (g)libc 中,例如在时间和日期函数中,例如 localtime,手册说:
The return value points to a statically allocated string which might be overwritten by subsequent calls to any of the date and time functions.
据我所知,我的程序是单线程的。使用“MT-Unsafe”函数(如 asctime 或 localtime)对我来说安全吗?
即使内存中只有1个(g)libc库实例? (即作为动态库。)
“静态”是否意味着“对我的程序静态”(为每个程序实例分配一个新的缓冲区实例..)、“对进程静态”(每个进程一个缓冲区实例 - this suggests )或静态到(libc)库(与库(-fragment)实例一样多的缓冲区实例)?
(我知道问题#8694365,但我的有点不同。)
最佳答案
全局(在函数外部定义)和静态(在函数内部定义)为每个程序分配一次。否则,asctime
将完全无法使用,因为您无法确定是否有另一个程序在您的程序同时调用该函数。
关于c - "statically allocated"在 libc 中到底意味着什么?每个库实例一个?每个程序实例一个?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42628182/