From kde-devel Tue Apr 26 23:35:17 2005 From: Felix Date: Tue, 26 Apr 2005 23:35:17 +0000 To: kde-devel Subject: Re: Newbie: Why does KMainWindow::show() hang?! Message-Id: <200504270135.18037.schmitt () voidcast ! de> X-MARC-Message: https://marc.info/?l=kde-devel&m=111455857210696 > [see first in thread for full problem report and code samples] > > (...) KMainWindow::show() hangs with mem consumption skyrocketing + > cpu load at > 1.0 (...) > Could anyone give me a hint what the most common causes would be? Once again, I screwed up, and I shouldn't have opened a new thread in the first place. This was the cause of the problem: - I have a class kbinfmt that inherits KMainWindow (see previous code examples). - in kbinfmt::kbinfmt(), another class kbinfmtView was initialized(see previous code examples). - in kbinfmtView::kbinfmtView(), yet another class FileTable was initialized, which inherits QTable. - In fileTable, "vector fileContents" holds a file which is --- eventually --- displayed on screen. - the reimplemented FileTable::resizeEvent() looks like this: 01 void FileTable::resizeEvent( QResizeEvent *e ) { 02 hexcols = (visibleWidth() - posSize) / (hexSize + textSize) / 4 * 4; 03 int nrow = (fileContents.size() - 1) / hexcols + 1; 04 setNumRows( (nrow > 16) ? nrow : 16 ); 05 setNumCols( hexcols * 2 + 1 ); 06 (...) 07 } Now, if I initialize fileContents to be empty, the following will happen: in line 03, fileContents.size() will return 0, BUT it will be of type size_type (see the STL docs), which is equivalent to unsigned int. So, the compiler casts everything to unsigned implicitly, and so 0 - 1 becomes not -1, but 2147483647. And these are rather many rows (line 04), which caused the excessive mem usage :-) ----------------------------- And Stefan, thanks for the hint, I'll take a look at KIO::storedGet/Put to see whether it is better than the old school stuff. Thanks all for your help Felix. >> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<