FastFormat - Memory Guessing Game

Links
Home
Download
SourceForge Project Website
Blog
Documentation
Help Forum
Request FastFormat training
Donate
Performance
Memory Guessing Game
STLSoft
Pantheios
 

Ultimate robustness!

  • 100% type-safe

Unlimited flexibility!

  • infinitely extensible

Unbeatable performance!

  • 5 - 17 times faster than Boost.Format
  • 1.5 - 5.5 times faster than Loki.SafeFormat
To whet your appetite, let's consider two examples. Your mission is to guess how many memory allocations are involved in each one.

First, with the fmt() API:
 { // fmt() API
  std::string sink;
  char        fastfmt[] = "FastFormat";
  long        year = 2008;

  fastformat::fmt(sink, "Releasing {0} in {1}?", fastfmt, year);

  assert("Releasing FastFormat in 2008?" == sink);
 }
Next, with the write() API:
 { // write() API
  char                      buff[100];
  fastformat::c_string_sink sink(100, &buff[0]);
  std::string               fastfmt = "FastFormat";
  long                      year = 2008;

  fastformat::write(sink, "Releasing ", fastfmt, " in ", year, "?");

  assert(0 == ::strcmp(buff, "Releasing FastFormat in 2008?"));
 }
Let's see how well you did. In the first example, there is one memory allocation - no you did not misread, that's 1 - as a result of a call to reserve() on the sink instance to ensure it has sufficient space to receive the formatted string.

Think that's a fluke, or some deliberately chosen unrepresentative example? In the second example there's one memory allocation in the std::string constructor for the instantiation of the fastfmt variable, and ... well, that's it. There are zero memory allocations involved in converting year into a string, and combining it with fastfmt and the three literal strings into the result.

We hope you're getting the picture. It's fast! ;-)

Because we're stupidly busy, we're likely to not be providing all the example/tutorial documentation you might want. If you post a question on the FastFormat Help forum or the STLSoft newsgroup we'll do our best to answer your question, and will add a corresponding example to the documentation for the next release.

Support This Project      Valid XHTML 1.0 Transitional