又说iconv

在多线程环境中,iconv本身是不支持多线程安全的。
比如在代码段中:

iconv_t cd = iconv_open(tocode, fromcode);
if (cd == (iconv_t)-1) {
exit(1);
}
iconv(cd, &inbuf, &len, &outbuf, &buflen);
iconv_close(cd);
多线程环境中,iconv_open不断打开资源,虽然iconv_close能够释放,但是并不能立即释放资源,这样造成内存泄漏。

比较正确的方法是静态地初始化iconv_open和析构iconv_close,或对上面代码段进行锁机制可实现线程安全。

Monthly Archives

Pages

Powered by Movable Type 7.7.2

About this Entry

This page contains a single entry by Cnangel published on June 3, 2009 1:29 AM.

Yum使用 was the previous entry in this blog.

CPAN对Perl模块进行编译 is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.