dbTalk Databases Forums  

locable.h: strange design dessision??

mailing.database.mysql-plusplus mailing.database.mysql-plusplus


Discuss locable.h: strange design dessision?? in the mailing.database.mysql-plusplus forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
pps
 
Posts: n/a

Default locable.h: strange design dessision?? - 09-19-2005 , 12:20 PM






Hi,
I tried to review some code inside mysqlpp and possibly modify it for me
(I want to replace some parts with code from other libraries, eg
boost.date_time etc, since I use date_time in my app) and I found some
strange code

class Lock, BasicLock, and Locable are strange pieces of code in my
point of view. First of all, there's no need to have virtual methods for
such simple class. Locable has a really doubtful piece of code - it
creates BasicLock using new! I find it to be really strange, as I don't
see any need to have pointer to an object that's one byte in size.
Perhaps, the intention was to have possibility replace underlying Lock
with some other Lock object, but isn't it's strange to change threading
models at runtime? As with my first mail I may be wrong without knowing
the underlying code, but why it was designed this way? I think I never
saw anything like this.
This issue is well discussed in "Modern C++ Design" and loki-lib has
some good code for implementing it.
basically, from this book it seem that a better decision is:
template<template <class> ThreadingModel>
class connection : ThreadingModel<connection> {}

and inside connection::method(){
lock(*this);
//do something...
}

--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw


Reply With Quote
  #2  
Old   
Warren Young
 
Posts: n/a

Default Re: locable.h: strange design dessision?? - 09-19-2005 , 12:28 PM






pps wrote:
Quote:
class Lock, BasicLock, and Locable are strange pieces of code in my
point of view.
That's because you don't understand the motivation, which isn't
surprising because it hasn't been documented anywhere but the Wishlist yet.

Quote:
First of all, there's no need to have virtual methods for
such simple class.
Yes, there is, because there will be an override someday.

Quote:
Locable has a really doubtful piece of code - it
creates BasicLock using new!
Read up on the pImpl idiom. (Also called Handle-Body, and other
things.) BasicLock is the current implementation, but in v2.1, there
will be alternate implementations for platforms that support locks. I
anticipate a Boost::Threads based implementation at least, and possibly
others. And there still must be a BasicLock implementation for those
platforms that do not support Boost::Threads, or where the user doesn't
want to install it.

Quote:
isn't it's strange to change threading models at runtime?
The purpose of hiding the implementation behind a pointer is so we can
change that implementation without breaking the library's ABI, which
adding data to a plain Lockable base class would do.

Quote:
I think I never saw anything like this.
See Advanced C++ by James Coplien.

--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw



Reply With Quote
  #3  
Old   
pps
 
Posts: n/a

Default Re: locable.h: strange design dessision?? - 09-19-2005 , 01:23 PM



Warren Young wrote:
Quote:
The purpose of hiding the implementation behind a pointer is so we can
change that implementation without breaking the library's ABI, which
adding data to a plain Lockable base class would do.

As far as I understand this will allow people to download newer
mysqlpp.dll and just replace it without rebuilding, am I correct?
What's ABI stands for??
How many overrides for this class there might be? (1 or 2 more).
Anyways, threadingmodel classes could be all inside headers without .cpp
files... if that solves this problem

--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw



Reply With Quote
  #4  
Old   
Warren Young
 
Posts: n/a

Default Re: locable.h: strange design dessision?? - 09-19-2005 , 02:04 PM



pps wrote:
Quote:
As far as I understand this will allow people to download newer
mysqlpp.dll and just replace it without rebuilding, am I correct?
Within a major version, yes, that's the idea.

Quote:
What's ABI stands for??
Application Binary Interface. That is, a program using a dynamic or
shared library version of MySQL++ has expectations such as object layout
that must be preserved within a major version. Essentially, we're
promising not to break the ABI until v3.x.

Quote:
How many overrides for this class there might be? (1 or 2 more).
I anticipate only 2 right now, both of which I mentioned in my previous
message.

Quote:
Anyways, threadingmodel classes could be all inside headers without .cpp
files... if that solves this problem
No, it doesn't help, because Lockable is used as a base class. If its
object layout changes, the ABI of classes derived from it also change.

--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.