Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Property Grid
  New Posts New Posts RSS Feed - Performance problem when deleting items from grid
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Performance problem when deleting items from grid

 Post Reply Post Reply
Author
Message
farr02 View Drop Down
Groupie
Groupie


Joined: 10 May 2005
Status: Offline
Points: 51
Post Options Post Options   Thanks (0) Thanks(0)   Quote farr02 Quote  Post ReplyReply Direct Link To This Post Topic: Performance problem when deleting items from grid
    Posted: 03 January 2008 at 4:00am
Hello,
in my application I noticed a performance problem when deleting a large number of elements from the grid via pItem->Remove();
Example:
First I create a large number of categories each holds two items:
CString sCatName;
g_pCustom = m_wndPropertyGrid.AddCategory(_T("Long Dialog"));
for(int i = 0; i < 512; ++i)
{
    sCatName.Format(_T("Category %03d"), i);
    CXTPPropertyGridItem* pCat =
        g_pCustom->AddChildItem(new CXTPPropertyGridItemCategory(sCatName));
    pCat->AddChildItem(new CXTPPropertyGridItemNumber(_T("Element 1"), i));
    pCat->AddChildItem(new CXTPPropertyGridItemNumber(_T("Element 2"), i));
    pCat->Expand();
}
g_pCustom->Expand();


Then I delete 'Element 1' in every category using the following code:
if(g_pCustom)
{
    CXTPPropertyGridItems* pItems = g_pCustom->GetChilds();
    if(pItems)
    {
        int i = pItems->GetCount() - 1;
        while (i >= 0)
        {
            CXTPPropertyGridItem* pCategory = pItems->GetAt(i);
            if(pCategory)
            {
                CXTPPropertyGridItems* pElements = pCategory->GetChilds();
                if(pElements)
                {
                    CXTPPropertyGridItem* pElement1 = pElements->GetAt(0);
                    if(pElement1)
                    {
                        // here 'Element 1' will be deleted
                        pElement1->Remove();
                        pElement1 = 0;
                    }
                }
            }
            --i;
        }
    }
}

The removal of the elements takes more than a minute in release configuration on a 3 GHz computer running Win XP and ToolkitPro v9.81, whereas creation time is less than a second.
Is something wrong with my code or takes the remove-function so much time?
(I think the problem may be the call to m_pGrid->Refresh(); in the remove function.)
How can I speed up the removal?

Bye
   Holger

Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post Posted: 03 January 2008 at 6:57am
Hi,
 
There are BeginUpdate, EndUpdate methods.
call them before/after your loop.
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS
Back to Top
farr02 View Drop Down
Groupie
Groupie


Joined: 10 May 2005
Status: Offline
Points: 51
Post Options Post Options   Thanks (0) Thanks(0)   Quote farr02 Quote  Post ReplyReply Direct Link To This Post Posted: 03 January 2008 at 10:41am
Hello Oleg,

I have already made some testing with Begin/EndUpdate before. When I just put them around the while-loop in the above code, the result is an empty grid. As far as I understood (please correct me if I am wrong) BeginUpdate stores some information about some grid states, disables refresh and redraw and finally deletes the whole grid. EndUpdate restores the saved states,  enables refresh and redraw and then redraws the grid. That means I have to rebuild my whole dialog inside a Begin/EndUpdate-block instead of just inserting or deleting a number of items into resp. from the existing dialog.

Maybe this is an item for the wish-list:
Implement a function that locks grid refreshing and redrawing during a bunch of insertion or removal operations without the need to rebuild the whole dialog.

Bye
   Holger

PS: I have forgotten in my first post: Happy New Year!
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post Posted: 03 January 2008 at 11:18am
oh, right, it deletes content.
 
ok, try this
 
 wndGrid.GetGridView().m_nLockUpdate = 1;
 wndGrid.GetGridView().SetRedraw(FALSE);
 
 wndGrid.GetGridView().m_nLockUpdate = 0;
 wndGrid.GetGridView().SetRedraw(FALSE);
 
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS
Back to Top
farr02 View Drop Down
Groupie
Groupie


Joined: 10 May 2005
Status: Offline
Points: 51
Post Options Post Options   Thanks (0) Thanks(0)   Quote farr02 Quote  Post ReplyReply Direct Link To This Post Posted: 04 January 2008 at 6:21am
Hi Oleg,
doesn't work
It leads to an access violation in CXTPPropertyGridView::_RefreshIndexes(). I have tried to eliminate the call to Refresh in the CXTPPropertyGridItem::Remove function but that gives me other errors.
So I think for the moment it is the best to stay with the current situation and hope for one of the next releases. Or do you have a better idea?

Thank you yery much.
Bye
   Holger
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post Posted: 04 January 2008 at 8:36am
Hi,
Think also you  need call Refresh() in the end.  (after SetRedraw(FALSE))
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS
Back to Top
farr02 View Drop Down
Groupie
Groupie


Joined: 10 May 2005
Status: Offline
Points: 51
Post Options Post Options   Thanks (0) Thanks(0)   Quote farr02 Quote  Post ReplyReply Direct Link To This Post Posted: 07 January 2008 at 4:50am
Hello Oleg,

doesn't work either:-(
I uploaded two files regarding the access violation: Number one ( uploads/20080107_042735_CJ_Fhut.zip ) is a crash dump file saved with WinDbg (WinDbg command: .dump /mFhut CJ_Fhut.dmp) and the second ( uploads/20080107_043556_ProblemItemRemo.zip )gives you a small description of the functions I inserted to the lib, and some more information about the access violation.

Hope it helps.
Bye
   Holger


Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post Posted: 08 January 2008 at 2:03am
Hi,
Last version to try: :)
 
void BeginUpdate()
{
    GetGridView().m_nLockUpdate = 1;
    GetGridView().SetRedraw(FALSE);
    GetGridView().().ResetContent();
}
void EndUpdate()
{
    GetGridView().m_nLockUpdate = 0;
    GetGridView().SetRedraw(TRUE);
    Refresh();
}
 
Think it will work fine.
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS
Back to Top
farr02 View Drop Down
Groupie
Groupie


Joined: 10 May 2005
Status: Offline
Points: 51
Post Options Post Options   Thanks (0) Thanks(0)   Quote farr02 Quote  Post ReplyReply Direct Link To This Post Posted: 08 January 2008 at 10:19am
Hi Oleg,

your are right: The code works fine.
Thank you very much.

Bye
   Holger

Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.172 seconds.