Where is the data stored? Or do you have to generate it? The smartest solution is to break it down into chunks, only 1000 rows at a time perhaps.

The lazy solution (assuming your computer has...