[bind10-dev] jelte status update

JINMEI Tatuya / 神明達哉 jinmei at isc.org
Fri Feb 5 20:04:30 UTC 2010


At Fri, 05 Feb 2010 12:48:40 +0100,
Shane Kerr <shane at isc.org> wrote:

> Fantastic! :)
> 
> This is perfect, although although even less detail is quite okay if it
> is too time consuming to make such a nice report. :)

Good news:-)

So are the rest of us supposed to send an update this week, too?

> > once the exceptions stuff has been moved out of isc::dns i can start
> > using it (oh and in fact i want to make isc::Exception have a
> > std::string instead of a char *, or i want a second one;
> > isc::RuntimeException that does). Some of the exceptions are already
> > using isc::dns::Exception now, but that creates a dependency on libdns.a
> > which is not necessary.
> 
> One question about this... do std::string objects use heap memory? If
> so, do we need to worry about leaks from exceptions then? (I guess using
> a shared_ptr is the way to avoid leaks in that case?)

I don't know if the standard requires the use of heap memory, but I
believe many if not all implementations of std::string allocates
memory for the string content dynamically.  But, in general (whether
or not it's used in the context of exceptions), we don't have to worry
about memory leak with std::string as it acts just like an STL
container in this sense.

One possibly more important implication in the context of exception is
that constructing the string itself isn't always exception free.  When
we do:

    if (something_wrong) {
        throw OurCustomException(std::string("bad thing happened"));
    }

The construction of exception string may also throw an exception
(e.g. std::bad_alloc).  It's not necessarily a catastrophic result,
but would make exception handling more complicated.

Also, if the implementation of OurCustomException is a straightforward
one:

class OurCustomException {
public:
	explicit OurCustomException(const std::string& what) : what_(what) {}
private:
	const std::string what_;
};

The construction of the internal copy of the what string may also
throw an exception, unless the copy is exception free (as in the case
where the std::string is implemented using a reference counter).

---
JINMEI, Tatuya



More information about the bind10-dev mailing list