Finding the slowdown

Tuesday, January 21st, 2003

…is a very satisfying thing. I finally pinned down what was causing a several second delay in eLibrary when the list is refreshed, and it has nothing to do with my new list control. It was buried in the array class I was using internally, a template class I use everywhere. I was using an Insert() function to add items to the end of the list, and the array class was rather stupidly creating a whole new list everytime I did this and copying itself across. Inserting items at the beginning of a large array is generally ineffecient, but there’s no reason why inserting at the end should be the same. Inserting 6000 items in this manner results in approximately 18 millions elements copied! That aint good.

STL stands for Standard Template Library. It is a handy collection of standardized classes for handling generic strings, lists, maps, arrays and lots of other stuff - more info here

Almost needless to say, it was my own oversight that was to blame. Instead of using an STL array I am using a home grown template which I wrote years ago. The reasons for this are (a) I started writing templates long before I understood exactly what the STL was, (b) even after I found out what the STL was, the code was still so terrifyingly hard to understand that I didn’t feel comortable using it, and (c) I have had a few problems in the recent past attempting to blend STL code with MFC code, so it’s easier to just stick with the homegrown. If the STL headers (at least those supplied with MSVC) weren’t so utterly alien looking to the average C programmer, they probably would have caught on a lot quicker. If you are a programmer trying to understand what’s nice about C++ templates, I would recommend not looking at the source for the STL classes, because they’ll probably just alarm you with their density and complexity.

feed

Leave a Comment

Name

Name

URL

URL