JPEG Thumbnailer

Ingo Klöcker kloecker at kde.org
Thu Aug 21 23:03:16 BST 2008


On Thursday 21 August 2008, Ingo Klöcker wrote:
> On Wednesday 20 August 2008, Thiago Macieira wrote:
> > Ingo Klöcker wrote:
> > >I know you will kill me for making the following suggestion. :-)
> >
> > Yes, I will. Using boost is an major overkill for this. Much more
> > than QFile, because QFile is in a library already loaded, while
> > boost will require additional code being loaded.
> >
> > >If QFile is too much overhead then I'd use a boost::shared_ptr
> > > with custom deleter [1], i.e.
> > >
> > >    boost::shared_ptr<FILE> fd_in( fopen(path.toLatin1().data(),
> > > "rb"), fclose ); if ( fd_in.get() == NULL )
> > >       return false;
> > >
> > >If you want to close the file explicitly then you call
> > > fd_in.reset(). Otherwise you don't have to do anything.
> > >
> > >Reasons for doing the above:
> > >a) We are coding in C++, right? So let's use the power C++
> > > provides. It makes no sense to write error prone code, if there's
> > > a way to avoid it.
> >
> > Uh... std::fstream?
>
> std::fstream does not seem to give access to the FILE handle, so it
> cannot be used in this particular situation.
>
> > >b) Using boost::shared_ptr is just a compile time dependency.
> >
> > Right, but it'll bring in all of boost's atomic reference counting
> > code along. Also remember that some compilers are brain-dead and
> > will instantiate the entire class, as opposed to just the parts of
> > it that you actually use.
>
> Which compilers? Do we care for those compilers?
>
> > Not to mention that a custom deleter would have to be written.
>
> In this particular case that's not true since
>   boost::shared_ptr<FILE> fd_in( fopen( "foo.jpg", "rb" ), fclose );
> works perfectly alright.
>
> > What you really want here is std::auto_ptr with a custom deleter.
> > There is no shared pointer in this circumstance, so no need to add
> > the overhead associated with that,
>
> True.

Actually, this is not true because unfortunately std::auto_ptr does not 
come with support for a custom deleter. I would have suggested 
boost::scoped_ptr instead of boost::shared_ptr, but boost::scoped_ptr 
also lacks support for a custom deleter. Or did you suggest to write an 
own version of std::auto_ptr with support for a custom deleter?


Regards,
Ingo
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 194 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20080822/e85ed25b/attachment.sig>


More information about the kde-core-devel mailing list