Wednesday, July 28, 2010

C++, STL, and brick walls

Two problems in one program today. Problem one: the program crashes on certain input files. Problem two: the program runs slowly.

I spent a good part of today tracking the crash problem in the spreadsheet libraries. The symptoms were easy to describe: the program works for small spreadsheets but not for large ones, where "large" is a number of about 200 MB. The cause was the use of "sizeof()" when I should have used "_countof()". (A subtlety of the Windows API for wide characters.) The investigation took much longer than I think it should have.

On the other hand, I did find the problem. The true problem. I made a correction that solves the problem and doesn't simply mask it. Go me!

The second problem is a harder one. The performance of C++ and STL is disappointing. It is much slower than I would like. It takes about four minutes to load a file, where the old libraries can load it in less than thirty seconds. The old libraries don't use STL; they use custom structures full of C++ pointers and other opaque techniques. The code is impenetrable and we don't understand how it all works.

The new code is understandable but slow.

Are these the only two possibilities? We want fast code that is maintainable. I need to think more about this problem.


No comments:

Post a Comment