## Archive for the ‘Question / Unsolved’ Category

### JSP & JSTL: Setting a Variable to the Content of an XPath

Wednesday, 21 October 2009

I had a problem in JSP and JSTL where I could not get a core variable to contain the content of an XML XPath expression.

Following a combination of reading a book, searching the Internet and speaking to a colleague, I found two solutions to my problem, but unfortunately not an answer to the question of why my original code does not work.

### STL Design Problem?

Thursday, 24 September 2009

Consider the following functions:

#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/date_time/date_facet.hpp>
#include <clocale>

std::string format_date_crash (::boost::gregorian::date dt)
{
std::locale locale_local ("");

::boost::gregorian::date_facet date_output;

std::ostringstream date_ss;

p_date_output.format("%x");
date_ss << dt;

return date_ss.str();
}

std::string format_date_leakquery (::boost::gregorian::date dt)
{
std::locale locale_local ("");

::boost::gregorian::date_facet * p_date_output
= new ::boost::gregorian::date_facet;

std::ostringstream date_ss;

(*p_date_output).format("%x");
date_ss << dt;

// *** don't delete p_date_output ***
return date_ss.str();
}

Here, I have used Boost too, but I don’t believe that the problem is in Boost.

Calls to format_date_crash() crash in the ~std::locale() destructor [oddly, I found that it crashes only on the second call].

On the other hand format_date_leakquery() looks as though it might leak: it has a new without a corresponding delete. However a test showed that it does not leak.

It seems that the std::locale constructor takes ownership of the facet, so that when the locale object is destroyed, so is the facet (ie. the facet is deleted).

Is this an instance of poor design in the STL, or is there some compelling reason that things are arranged this way?

### SVN Tip: Diffs on Windows without Tortoise

Tuesday, 28 July 2009

Sometimes it’s convenient to be able to view modifications to a file in a file difference GUI on a Windows machine on which it is undesirable to install TortoiseSVN. Here’s a way to do it…

### Generalised Means

Tuesday, 2 June 2009

There are many notions of average in mathematics and statistics. Well-known are the mean, median and mode.

Also well-known, amongst the means, are the arithmetic mean (A), geometric mean (G), harmonic mean (H) and quadratic mean or  root mean squared (Q or RMS). Recently, I have become interested in the notion of a generalised mean (or generalized mean) over positive (non-negative and non-zero) real numbers $\in \mathbb{R}^+$.

### Generalisations of Calculus

Tuesday, 2 June 2009

There are various ways in which the integral and differential operators may be generalised or varied.