In article <4773AFA2.2080201@crystalclearsoftware.com>,
Jeff Garland
Richard wrote:
In article <4772F58B.8080908@crystalclearsoftware.com>, Jeff Garland
writes: The new is NOT superfluous. The constructor of std::locale takes a pointer to a reference counted facet -- effectively taking ownership of the memory.
Does it call delete on it?
Yes -- there's an internal reference count in the facet so that facets can be shared by multiple streams.
And No -- if you pass a positive value for the reference count to the facet c'tor then it doesn't call delete on the pointer. So you could do that code without calling new as follows: int main() { ptime t1(date(2007, Dec, 26), hours(1) + seconds(5) + milliseconds(9)); time_facet timefacet("%a, %d %b %Y %H:%M:%S %z", time_facet::period_formatter_type(), time_facet::specialvalues_formatter_type(), time_facet::date_gen_formatter_type(), 1); std::cout.imbue(std::locale(std::locale::classic(), &timefacet)); std::cout << t1 << std::endl; //Wed, 26 Dec 2007 01:00:05 } Which is admittedly more clunky to work with, but then again all the locale stuff feels that way to me. I'm not sure if you need to reverse the effects of the imbue before you leave main() either, that might be something else that locales require for this to work properly. -- "The Direct3D Graphics Pipeline" -- DirectX 9 draft available for download http://www.xmission.com/~legalize/book/download/index.html Legalize Adulthood! http://blogs.xmission.com/legalize/