小编Fel*_*ipe的帖子

提升精神内存泄漏

我正在编写一个小程序来处理一个大文本文件并进行一些替换.问题是它永远不会停止分配新的内存,所以最终它会耗尽内存.我已经将它简化为一个简单的程序,只需计算行数(参见下面的代码),同时仍然分配越来越多的内存.我必须承认,我对提升和提升精神知之甚少.你能告诉我我做错了什么吗?太感谢了!

#include <string>
#include <iostream>
#include <boost/spirit/include/lex_lexertl.hpp>
#include <boost/bind.hpp>
#include <boost/ref.hpp>
#include <boost/spirit/include/support_istream_iterator.hpp>

// Token ids
enum token_ids {
    ID_EOL= 100
};

// Token definition
template <typename Lexer>
    struct var_replace_tokens : boost::spirit::lex::lexer<Lexer> {
        var_replace_tokens() {
            this->self.add ("\n", ID_EOL); // newline characters
        }
    };

// Functor
struct replacer {
    typedef bool result_type;
    template <typename Token>
    bool operator()(Token const& t, std::size_t& lines) const  {
        switch (t.id()) {
        case ID_EOL:
            lines++;
            break;  
        }
        return true;
    }
}; 

int main(int argc, char **argv) { …
Run Code Online (Sandbox Code Playgroud)

c++ boost memory-leaks boost-spirit

2
推荐指数
1
解决办法
344
查看次数

标签 统计

boost ×1

boost-spirit ×1

c++ ×1

memory-leaks ×1