Im using the Qt regex utilities to match and capture data from an input 
string.  I get a new String every couple of milliseconds and have to run 
the same regex over it each time.  It works great for awhile, but will 
randomly crash at points and I can't figure out why.  There are no 
exceptions, it just kills the jvm.  The reason I switched to the Qt 
regex engine from the java regex engine is the java regex engine was 
causing a memory leak and had allocated over 20mb worth of boolean[] 
arrays.  It seems to be happening with the exactMatch and cap(int) 
methods and I can not figure out how to reproduce it or what causes as 
it happens like once out of a few thousand input strings.  My crash logs 
always show one of two things on the stack, either:

Stack: [0x06020000,0x06070000],  sp=0x0606f8a0,  free space=318k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, 
C=native code)
C  [ntdll.dll+0x659c3]
C  [ntdll.dll+0x65883]
C  [kernel32.dll+0x4c56f]
C  [msvcrt.dll+0x9d6b]
C  [QtCore4.dll+0x167b43]
C  [QtCore4.dll+0x167cb0]
C  [QtCore4.dll+0x4e0ef]
C  [QtCore4.dll+0x4e298]
C  [com_trolltech_qt_core.dll+0x7a9df]
J  
com.trolltech.qt.core.QRegExp.__qt_exactMatch_String(JLjava/lang/String;)Z
J  com.trolltech.qt.core.QRegExp.exactMatch(Ljava/lang/String;)Z

or:

Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, 
C=native code)
V  [jvm.dll+0xcf007]
C  [com_trolltech_qt_core.dll+0x7a75f]
J  com.trolltech.qt.core.QRegExp.__qt_cap_int(JI)Ljava/lang/String;
J  com.trolltech.qt.core.QRegExp.cap(I)Ljava/lang/String;

// source (i know these regex patterns arn't the most efficient, but 
faster than using String methods)
    private final String AREGEX = 
"[A:\\s]*([\\d.]*)[\\s]*\\([\\d.:]*\\)[\\s](?:of[\\s]*[\\d.]*[\\s]*\\([\\d\\s.:]*\\)|)[\\s]*([\\d.?,]*)%(?:[\\s]*([\\d.]*)%|)(?:[\\s]*([\\d.]*)x.*|.*)";
    private final String REGEX = 
"[A:\\s]*([\\d.]*)[V:\\s]*([\\d.]*)[A\\-V:\\s]*([\\d.\\-]*)[ct:\\s]*([\\d.\\-]*)[\\s]*([\\d]*)[\\s]*/[\\s]*([\\d]*)\\s*([\\d.?]*)[%\\s]*([\\d.?]*)[%\\s]*([\\d.?]*)[%\\s]*([\\d]*)\\s([\\d]*)[\\s]*([\\d]*)[%\\s]*(?:([\\d.]*)x.*|.*)";
//...
private QRegExp aregex = new QRegExp(AREGEX);
private QRegExp regex = new QRegExp(REGEX);
//...
if (aregex.exactMatch(line)) {
try {
                cfile.audio_position = Double.parseDouble(aregex.cap(1));
                cfile.ac_cpu_time = Double.parseDouble(aregex.cap(2));
                String mat = aregex.cap(3);
                if (mat != null && !mat.equals("")) {
                    cfile.cache_use = Integer.parseInt(mat);
                }
                mat = aregex.cap(4);
                if (mat != null && !mat.equals("")) {
                    cfile.playback_speed = Double.parseDouble(mat);
                }
            } catch (NumberFormatException ex) { }
}
else if (regex.exactMatch(line)) {
            try {
                cfile.video_position = Double.parseDouble(regex.cap(2));
                cfile.audio_position = 
Double.parseDouble(regex.cap(1).trim());
                cfile.avsync = Double.parseDouble(regex.cap(3));
                cfile.avcorrection = Double.parseDouble(regex.cap(4));
                cfile.frames_rendered = Integer.parseInt(regex.cap(5));
                cfile.frames_decoded = Integer.parseInt(regex.cap(6));
                cfile.frames_buffered = cfile.frames_decoded - 
cfile.frames_rendered;
                cfile.vc_cpu_time = Double.parseDouble(regex.cap(7));
                cfile.vo_cpu_time = Double.parseDouble(regex.cap(8));
                cfile.ac_cpu_time = Double.parseDouble(regex.cap(9));
                cfile.correction_frame_drop = 
Integer.parseInt(regex.cap(10));
            } catch (NumberFormatException ex) { }
}

    Thanks,
    - Dave
_______________________________________________
Qt-jambi-interest mailing list
[email protected]
http://lists.trolltech.com/mailman/listinfo/qt-jambi-interest

Reply via email to