List:MySQL++« Previous MessageNext Message »
From:Byrial Jensen Date:May 29 2005 5:28pm
Subject:Optimization of Row (patch attached)
View as plain text  
Hi,

When a Row object is constructed, it will copy all data of the fetched
row of type MYSQL_ROW to a vector of std::string. That seems to me as
unnecessary use of time and memory. The row data is only accessed
through pointers to const char:
   * Row::raw_data() returns a pointer obtained from std::string::data()
   * Row::operator[]() uses a pointer obtained from std::tring::c_str() 
to initialize the returned ColData object.

The attached patch will store the MYSQL_ROW and directly get the
pointers to data from it in raw_data() and operator[]().

There should be only one visible change to the endusers, and
that is a good one:
   * The pointer returned by raw_data() will with the patch point to a
NUL-terminated string (coming directly from the MYSQL_ROW object given 
by mysql_fetch_row()). The pointer currently returned is fetched by
std::string::data() and therefore not NUL-terminated. This change means
that a user who wants a raw pointer to a NUL-terminated column data, now 
can use raw_data() instead of creating of a ColData object with 
operator[]() - which also copies the data - and in that way avoid that 
data from, say, large BLOB database types is copied twice.

I have a program where this patch gives more than 20 % decrease of the
execution time (from 99 down to 77 seconds) when it runs on an otherwise
idle Linux box.

Best regards
Byrial


Attachment: [text/x-patch] row.patch
Thread
Optimization of Row (patch attached)Byrial Jensen29 May
  • Re: Optimization of Row (patch attached)Chris Frey29 May
    • Re: Optimization of Row (patch attached)Chris Frey30 May
      • Re: Optimization of Row (patch attached)Warren Young8 Jul
        • Re: Optimization of Row (patch attached)Warren Young8 Jul
    • Re: Optimization of Row (patch attached)Byrial Jensen30 May
      • Re: Optimization of Row (patch attached)Chris Frey31 May