IsBadXxxPtr Is Really Harmful – Please Don’t Use These Functions

January 15, 2010

You might have stumbled upon posts like this one that tell you there’s a simple solution for verifying that a memory location is OK for read/write/execution: Just use the “IsBadXxxPtr” family of functions that take a memory address and return a BOOL indicating if you can use the memory. It turns out (and I’m hardly the first to blog about it) that calling these functions causes more problems than it solves, and causes bugs rather than fixes them. Please heed the collective advice and stay away from these APIs. Here are some reasons why: Non-atomicity ...
no comments

Generating Prime Numbers in a Range (Was: LINQ Challenge), Part 4 – More on Sieves

As it is often the case with algorithms, there’s a better one yet for the problem at hand. The Sieve of Eratosthenes that we employed in the previous step is significantly faster than naively testing every prime number in the range, but there are additional improvements on this approach. The Sieve of Atkin is a much smarter algorithm that relies on certain properties of modulo-sixty remainders of prime numbers. The algorithm is based on the following facts (and do feel free to check the Wikipedia entry for more details): All numbers with a modulo-sixty...
no comments

Generating Prime Numbers in a Range (Was: LINQ Challenge), Part 3 – Sieve Me One

January 14, 2010

It’s time for the big guns. We’ve already seen simple optimizations to the problem of generating the prime numbers in a range. A completely different approach, the Sieve of Eratosthenes, is based on a very simple idea. Write down all the numbers in the range {1…N}. Mark 2 as prime. Now strike out every multiple of 2 as composite. Move on to the next number that is not marked as composite yet, and strike out every multiple of it as composite. (The next number, incidentally, is 3; then 5; then 7; and so on.) After Sqrt steps...

Generating Prime Numbers in a Range (Was: LINQ Challenge), Part 2 – Simple Optimizations

January 12, 2010

There are two rather trivial optimizations to the problem of generating prime numbers that we saw in the previous post. First there’s the observation that it suffices to test all potential divisors in the range {2…Floor]} to ascertain that K is prime. This is not much harder to accomplish and is a significant running time optimization: static int Sqrt(IEnumerable<int> range) {     return range.Where(n =>     {         if (n == 2) return true;...
no comments

Generating Prime Numbers in a Range (Was: LINQ Challenge), Part 1 – Introduction

January 11, 2010

Justin Etheredge posted a nice LINQ challenge – write a LINQ query, using whatever chained lambdas you want, but no custom LINQ methods, to generate the prime numbers in a given range. Over at his blog, Justin analyzes a couple of possible implementations with real LINQ queries (although the more efficient of them will have fairly complex lambdas in the query). I, on the other hand, would like to focus on the lessons you can learn from this kind of simple exercise, without using LINQ queries for now. Here are the rules of engagement for this mini-series...
no comments

Beware of Evil Wizards

January 9, 2010

Ten years ago, Andrew Hunt and David Thomas published the incredible book, “The Pragmatic Programmer: From Journeyman to Master”. It’s not that I like this book because it has taught me so many things; I mainly like this book because of what it has not taught me. And one thing this book has not taught me is to use Add New Item –> “Some Amazing Technology” Class Template and then just adjust the grid on the control ever so slightly, and bam – there’s your user interface in all its glory. Here’s what “The Pragmatic Programmer” has...

C++ in Visual Studio 2010: Windows Platform Developers User Group

January 7, 2010

Almost two years ago, I wrote about the TR1, a set of additions to the C++ standard that was implemented in a Feature Pack for Visual Studio 2008. Back then, I gave the post a rather provocative title: C++ Developers Just Got Lambdas? Well, now we’ve got them. The new C++ standard, dubbed C++0x (where the x is going to be a hexadecimal digit, hopefully A) has lambda functions as one of its features. Visual Studio 2010 implements some of the standard (draft), including lambda functions. Yesterday I had the pleasure of presenting C++0x to a group...
one comment

SDP 2009: .NET Debugging Tutorial

January 2, 2010

A few days I delivered a full-day session titled “Debugging .NET Applications” at the Sela Developer Practice. The session was packed and I was really happy to see lots of people interested in .NET debugging – this seems to be an area of incessant popularity. I only had one day to deliver lots of material – I basically tried to cram the entire .NET Debugging course I teach at Sela into a single day. We started with debugging basics such as dump files and symbols – and considering the dozens of ways to capture a dump...
no comments

SDP 2009: Parallel Programming with .NET 4.0 and Visual Studio 2010

A few days ago, at the Sela Developer Practice, Eran and I delivered a session titled “Parallel Programming with .NET 4.0 and Visual Studio 2010”. In this session we wanted to highlight the new features for parallel programming in .NET 4.0 – the Task Parallel Library and PLINQ – as well as the new Visual Studio 2010 features in the debugging and profiling areas. We started with what we call explicit parallelism – manually creating tasks and specifying what to do when they execute and when they complete. We used tasks to show some neat design...
no comments

SDP 2009: Building Workflow Services with WF 4.0 and WCF 4.0

Eran and I delivered a session titled “Building Workflow Services with WF 4.0 and WCF 4.0” at the Sela Developer Practice on Tuesday. This session was all about integrating the new features of WF 4.0 and WCF 4.0 to create a workflow application that orchestrates the execution of multiple WCF services. During the session, we showed how to use WCF 4.0’s ad-hoc discovery, how to write declarative workflows and use custom activities, how to take advantage of the built-in messaging activities in WF 4.0 and how to integrate a workflow application into Windows Server AppFabric....
tags: , , ,
one comment