phobos / tango / ares

kris foo at
Sat Feb 10 20:43:18 PST 2007

Charles D Hixson wrote:
> I'm not sure whether you were quoting the documentation, or reporting 
> your understanding.  If you were quoting the documentation, I think it 
> needs editing.

 From the doc: "Please note that the class itself is stateful, and 
therefore a single instance is not shareable across multiple threads."

Thus, it is considered unwise to share a single instance of Sprint 
across multiple threads. However, multiple threads /can/ share a single 
instance if they follow this pattern:

synchronized (GlobalSprint)
               GlobalSprint ("do my formatting", with, these, args);

This is a fairly standard mechanism in D for sharing resources across 
threads, and it's what I had referred to.

But there's no reason to do this kind of thing at all. The use-case for 
Sprint is to keep a handy formatter around for doing fast and convenient 
layout. Adding synchronized to the mix tends to defeat one of those 
desirable attributes, so we don't recommend it :)

If you're content to stash layout content into a temporary buffer 
instead, there's Formatter.sprint() which takes an output array. The 
output array in such a case would typically be stack-based.

More information about the Digitalmars-d-learn mailing list