简体   繁体   English

QRegularExpression匹配内存消耗

[英]QRegularExpressionMatch memory consumption

here is part of my code: 这是我的代码的一部分:

    int Parser::SomeFunction(const QString &line, int start, int& fieldStart, int& fieldLength ) const
{
    int end;
......
    if (0 == m_pRegExp)
    {
......
    }
    else
    {
#ifdef KNOWN_PATTERN
        end = 19;
#else

        QRegularExpressionMatch match = m_pRegExp->match(line,  start);
        if (!match.hasMatch())
        {
            return 0;
        }

        // currently we are requiring match to be found exactly at the position 'start'
        if (match.capturedStart() != start)
        {
            return 0;
        }

        end = match.capturedEnd();
#endif
    }
.....
}

The program loads a text file and parses its lines one by one. 该程序将加载一个文本文件,并逐行分析其行。 The whole purpose of code in 'else' scope is to calculate where a field ends (integer 'end') in the next line passed to the function. “其他”范围内的代码的全部目的是计算在传递给函数的下一行中字段的结束位置(整数“ end”)。 When I compile with KNOWN_PATTERN #defined and load some test file, for which I know 'end' should become 19, my program consumes about 400 MB less memory than when compiled without KNOWN_PATTERN #defined. 当我使用KNOWN_PATTERN #defined进行编译并加载一些测试文件时,我知道其“结束”应为19,与不使用KNOWN_PATTERN #defined进行编译时相比,我的程序消耗的内存少约400 MB。 400 MB is what all lines of my test file occupy in the memory (I can can calculate it based of file size and also I watched memory consumption when file was loaded and before parsing started). 我的测试文件的所有行都占用了400 MB的内存(我可以根据文件大小来计算它,也可以在加载文件时以及开始解析之前观察内存消耗)。 So it seems to me that QRegularExpressionMatch creates a copies of each line and does not release it. 因此在我看来QRegularExpressionMatch创建每行的副本,但不释放它。 What am I missing here? 我在这里想念什么? Thanks! 谢谢!

Task Manager and similar are very blunt tools for observing memory allocation by the C++ runtime. 任务管理器和类似工具是非常钝的工具,用于观察C ++运行时的内存分配。

In particular, the runtime doesn't necessarily release deallocated memory back to the OS, as OS memory allocation is relatively slow on many platforms, but holds on to it for itself. 特别是,运行时不一定会将释放的内存释放回OS,因为在许多平台上OS内存分配相对较慢,但可以自行保留。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM