[Interest] QRegularExpressionMatch memory consumption

Michael Videlgauz michael at videlgauz.com
Sat Oct 12 11:28:01 CEST 2013

Hello all,
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)
        end = 19;

        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();

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!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20131012/350c6987/attachment.html>

More information about the Interest mailing list