Board index » cppbuilder » ProcessMessages() in a loop
Vladimir Stefanovic
![]() CBuilder Developer |
ProcessMessages() in a loop2005-03-04 01:37:06 AM cppbuilder19 Hi, I have a database (with data, of course) which structure was not adequate to me. So I decided to transform it's data in the way I want. The database itself is pretty big (for MS Access ;) - a couple of tables every with about 400,000 records. I haven't used the standard DB mechanisms for seraching for matches (Lookup, Locate), because I found working with TStringList-s signifficantly faster. Then, I made a utility which: 1) transfers the data to TStringList-s 2) processes that TStringList-s 3) transfers data from TStringList-s back to DB. The problem is that utility worked 98% correct which is rediculous. The 2% of data was processed wrong. I'm wondering if such code skeleton can in some circumstances become bad, because of ProcessMessages(), or something else: for ( int i=0; i<400000; i++ ) { Application->ProcessMessages(); // Here, I had few TStringList objects' manipulations // on very big (400,000 items) objects of TStringList // like SomeIndex = SL1->IndexOf( ... ), // SL2->Strings[ SomeIndex ] = ..., // etc, ... } At the beginning, loop processed about 2000 recors / second but as the destination TStringList become bigger, it processed only a few records / second (because IndexOf() now had more job to do) Once, the destination TStringList was full of duplicated entries, like:'sometextsometext' instead of 'sometext'. Sometimes, the destination TStringList was short for maybe of 1000 consecutive records. There were also some other misterious results. Can ProcessMessages() be dangerous in this case? Should I use CriticalSections in this transformations, like: for ( int i=0; i<400000; i++ ) { Application->ProcessMessages(); EnterCS Processing ... LeaveCS } -- Best regards, Vladimir Stefanovic |