我知道。 Xpressive在这里可能(可能)没有错,但是我在寻找内存泄漏方面付出了很多努力,我不得不调整代码布局来修复出血。“压力泄漏”固定,但不明白
有人可以向我解释为什么布局的改变修复了吗?我不明白为什么(正确/改进)使用“静态常量”来修复泄漏。
顺便说一下,泄漏发生在MIPs核心上,使用boost版本1.49,并与GCC 4.3.3交叉编译。
原始 “筛子” 代码:
// source.cpp
#include <boost/...
cregex token = keep(+set[ alnum|'!'|'%'|'_'|'*'|'+'|'.'|'\''|'`'|'~'|'-']);
cregex more = ...
bool foo(const char * begin, const char * end, size_t& length, std::string& dest)
{
mark_tag name_t(1);
cregex regx = bos >>
icase("name:") >>
(name_t= token) >> eos;
cmatch what;
bool ok = regex_search(begin, end, what, regx);
...
return ok;
}
固定 “不露” 代码:
// header.hpp
#include <boost/...
class Xpr {
public:
static const cregex token;
static const cregex more;
};
// source.cpp
#include "header.hpp"
const cregex Xpr::token = keep(+set[ alnum|'!'|'%'|'_'|'*'|'+'|'.'|'\''|'`'|'~'|'-']);
const cregex Xpr::more = ...
bool foo(const char * begin, const char * end, size_t& length, std::string& dest)
{
mark_tag name_t(1);
static const cregex regx = bos >>
icase("name:") >>
(name_t= Xpr::token) >> eos;
cmatch what;
bool ok = regex_search(begin, end, what, regx);
...
return ok;
}
泄漏似乎在富的每一个呼叫正在发生!
感谢您花时间做出回应。如果我要发布真实的代码,我的雇主可能不会太感动,对不起。 经过进一步测试后发现,即使在函数“foo”中使用static const也不足以完全阻止泄漏。 但我没有看到来自Xpr类静态const成员(还)的任何泄漏。 我的猜测是迈向MIPS版本的GCC中的一些“流氓软件”。我也**不能**重现“偏离目标” – GreyMattR 2012-08-08 13:43:19