[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: Newbie: Why does KMainWindow::show() hang?!
From:       Felix <schmitt () voidcast ! de>
Date:       2005-04-26 23:35:17
Message-ID: 200504270135.18037.schmitt () voidcast ! de
[Download RAW message or body]


> [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<char> 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 <i/ofstream> stuff.


Thanks all for your help

Felix.
 
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic