简体   繁体   中英

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. 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. 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). So it seems to me that QRegularExpressionMatch creates a copies of each line and does not release it. What am I missing here? Thanks!

Task Manager and similar are very blunt tools for observing memory allocation by the C++ runtime.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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