August 20, 2003

More Fun With CodeDOM

In a recent debate over writing the n very similar algorithms by hand (one for each number of inputs) vs. writing a data-driven algorithm to handle any number of inputs, Peter takes the middle route using the .NET CodeDOM to generate the simple algorithm for the required number of inputs at run-time. What makes this interesting isn't the result, which didn't turn out to be the most efficient, but the approach itself, which is unique to metadata-enabled systems and something I completely forgot even existed. Thanks for the reminder, Peter!
August 20, 2003

Startup, Shutdown & related matters

Apparently cbrumme was backed up after two weeks fighting the blaster virus internally, because he lets loose with a tour de force of details about managed and unmanaged startup and shutdown as well as a trailer on writing secure code in general. Fun to read if you like this level of detail (and the part about secure code at the end should be read by everyone).
August 20, 2003

PowerPoint Is Evil (Not!)

I've seen this kind of argument before, blaming presentation software (or PowerPoint specifically) for making people stupid. If PPT didn't allow you to make intelligent presentations, then I'd be all for panning it, but that's not true. PowerPoint can be used for good or for evil, but it's only a tool; it's the presenter that decides the use to which the tool is put.
August 20, 2003

How much is your brain worth?

ShawnMor documents his hangover from a hd crash w/o a recent backup, collecting backup schemes from contributors to avoid this problem in the future. I wonder how users that don't program computers for a living deal with this problem if we have trouble?
August 19, 2003

Career Calculus

There's just so much good advise in this post and it covers so much ground that I can't even think of a clever summary. Just go read it.
August 19, 2003

Not Missing Duff’s Device

This isn't new, but the wacky C/C++ Duff’s Device came up again in my circles. I really don't miss using a language that allows such things. Thank you for C#, Anders.
August 19, 2003 Spout

Buffering .NET Console Output

Doing some ad hoc benchmarks, I found that my compute/IO intensive program was significantly slower in .NET than in native C++ (here’s a more rigorous test showing the same thing). However, when the IO was taken out (Console.Write), the test showed that the computation in .NET and in native C++ was nearly the same (with C++ still having a slight edge).

My .NET IO code looked like this:

static void OutputIt(int[] vect) {
  for (int i = 0; i < vect.Length; ++i) {
    if( i > 0 ) Console.Write(”,“);
    Console.Write(vect[i]);
  }
  Console.WriteLine();
}

In tracking down this disparity, Courteney van den Berg noticed that, unlike STL IO streams in native C++, .NET Console output is not buffered. A simple manual buffering using a StringBuilder brings the performance of .NET back in line with native C++:

static void OutputIt(int[] vect) {
  StringBuilder sb = new StringBuilder();
  for (int i = 0; i < vect.Length; ++i) {
    if( i > 0 ) sb.Append(”,“);
    sb.Append(vect[i]);
  }
  Console.WriteLine(sb);
}

Instead of buffering manually, I could have turned on buffered console IO by reopening console output with a buffer size:

static void Main(string[] args) {
  using( StreamWriter bufferOutput = new StreamWriter(Console.OpenStandardOutput(1024)) ) {
    Console.SetOut(bufferOutput);
    // Use Console.Write (via OutputIt)…
  }
// Remaining buffered Console output flushed
}

// Console output now buffered
static void OutputIt(int[] vect) {
  for (int i = 0; i < vect.Length; ++i) {
    if( i > 0 ) Console.Write(”,“);
    Console.Write(vect[i]);
  }
  Console.WriteLine();
}

Why isn’t Console output buffered by default? Unlike in C++, which has deterministic finalization, in .NET, console output would have to be manually flushed or closed (closing causes a flush). Failure to do so can cause console output to be incomplete at the end of a program. Notice our careful use of the “using” block in the code above, causing the output stream to be closed at the end of the block and the remaining buffered output to be flushed, even in the face of exceptions. Forgetting to use the “using” block or forgetting to manually flush or close in a finally block, can cause console output to be lost. Rather than imposing the new burden of manually closing the console output, .NET architects opted to turn off buffering by default, while still letting you turn it on at will.

August 18, 2003

Protect Your Friends’ & Families’ PCs

Nobody reading this site needs any help protecting themselves from the blaster virus or any other kind, but those of you with families and friends having trouble, point them at Microsoft’s Protect your PC site.

← Newer Entries Older Entries →