|
From: Jonathan W. <my...@ka...> - 2007-03-01 10:12:51
|
On 01/03/07, Andrew Tomczak <ato...@aj...> wrote:
> I would like to propose a group of changes.
[snip]
> This way the a connection on the heap can be made by using the command
>
> mysqlcppapi::Connection *con = new mysqlcppapi::Connection(
> "localhost", "username", "password", "databasename");
>
> This is less wordy then all the lines used to create a connection.
This could be done without changing the API at all, using factory functions:
std::auto_ptr<Connection>
createConnection(std::string const& host, std::string const& user)
{
std::auto_ptr<Connection> conn(new Connection);
conn->set_Host(host);
conn->set_User(user);
}
What's wrong with something like that?
>
> Making connections and queries on the heap brings up another item. But
> before I go into that I need to give a reason for this.
> The reason to create these things as pointers on the heap is that they
> can be created and deleted by the program running them without creating
> memory leaks, while keeping the memory footprint to a minimum. The most
> important thing is to be able to hold the classes loosely coupled. This
> way a query can be made, drop the data into the result set and then be
> deleted. This leaves a small memory footprint.
You haven't explained why any of that needs to be done on the heap.
"Without creating memory leaks" is not an emergent property of using the heap!
>
> So the problem with this, is the function:
>
> Query Connection::create_Query()
> {
> return Query(*this);
> }
>
> It cannot be overloaded, so the next best thing is:
>
> Query *Connection::create_new_Query()
> {
> return new Query(*this);
> }
>
> Using the function above, a query on the heap can be using the command
>
> mysqlcppapi::Query *query = con->create_new_Query();
>
> Another option is to remove it or go without it, using:
>
> mysqlcppapi::Query *query = new Query(con);
Why is doing that a problem?
Or, slightly less efficient, but nice and simple:
std::auto_ptr<Query> q(new Query(conn.create_Query());
> I am going to be making a lot of changes and adding features to my copy
I don't see the need for either of these changes, they increase the
number of public functions without adding any functionality that is
not already available.
What am I missing?
jon
|