Re: memory lead while using Glib regexp



On 03/02/2012 04:00 AM, Xi Yang wrote:
Hi, everyone!


I use Glib's regular expression in a cycle, and find a rapid memory consumption increase. Did I forget to 
release anything?

since nobody replied I'll give it a shot (without any C++ knowledge):

does seq.header.c_str() return a newly allocated string?


Olivier




Thanks a lot!


================= code below ======================


GRegex* regex_illumina = g_regex_new(
     "@(.+):(\\d+):(\\d+):(\\d+):(\\d+)#(\\d+)/([12])",
     G_REGEX_OPTIMIZE,
     GRegexMatchFlags(0),
     NULL
);


GRegex* regex_casava_1p8 = g_regex_new(
     "@(.+):(.+):(.+):(\\d+):(\\d+):(\\d+):(\\d+) ([12]):([YN]):\\d+:(\\w*)",
     G_REGEX_OPTIMIZE,
     GRegexMatchFlags(0),
     NULL
);


// inside cycle body
         gchar* tile_str;
         int tile;
         GMatchInfo* what;

         // match and fetch something
         if ( g_regex_match(regex_illumina, seq.header.c_str(), GRegexMatchFlags(0),&what) ) {
             tile_str = g_match_info_fetch(what,3);
         }
         else if ( g_regex_match(regex_casava_1p8, seq.header.c_str(), GRegexMatchFlags(0),&what) ) {
             tile_str = g_match_info_fetch(what,5);
         }
         else {
             throw runtime_error("failed to parse header line:\n"+seq.header);
         }


         // parse a number
         if (sscanf(tile_str,"%d",&tile)!=1)
             throw runtime_error("failed to fetch tile from "+seq.header);


         // release match info and fetched string
         g_match_info_free(what);
         g_free(tile_str);
// end of cycle body
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]