|
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
Dr.Disrespect Grandmaster Cheater Reputation: 3
Joined: 17 Feb 2016 Posts: 526
|
Posted: Mon Mar 06, 2017 12:23 am Post subject: Loading items into a listview -- performance issue. |
|
|
I am using the following function to load data into a listview (I copied it from a post on this forum):
Code: |
function addLevelItem(control, level, one, two, three, four, five , six, seven)
local lvitems=listview_getItems(control)
local item=listitems_add(lvitems)
local subitems=listitem_getSubItems(item)
listitem_setCaption(item,level)
strings_add(subitems, one)
strings_add(subitems, two)
strings_add(subitems, three)
strings_add(subitems, four)
strings_add(subitems, five)
strings_add(subitems, six)
strings_add(subitems, seven)
end
function LoadDate()
for i=1,200 do
..... <-----get data from memory
addLevelItem(......) <-------------use the function to add data into listview
end
end
|
The problem is the lack of performance(speed). The trainer lagged a bit even when I was only loading less than 200 entries. Is there a way to speed it up? What is the cause of the lag, is it because that I get items from control in every loop?
Thanks.
_________________
**************
A simple example is better then ten links. |
|
Back to top |
|
|
atom0s Moderator Reputation: 199
Joined: 25 Jan 2006 Posts: 8518 Location: 127.0.0.1
|
Posted: Mon Mar 06, 2017 2:03 am Post subject: |
|
|
Make use of the beginUpdate/endUpdate calls before and after you start adding items to the ListView to prevent it from redrawing each item that is inserted until you are finished. Should speed things up.
_________________
- Retired. |
|
Back to top |
|
|
Dr.Disrespect Grandmaster Cheater Reputation: 3
Joined: 17 Feb 2016 Posts: 526
|
Posted: Mon Mar 06, 2017 10:56 am Post subject: |
|
|
atom0s wrote: | Make use of the beginUpdate/endUpdate calls before and after you start adding items to the ListView to prevent it from redrawing each item that is inserted until you are finished. Should speed things up. |
Thanks for the reply. Do you mean this?
Code: |
function addLevelItem(control, level, one, two, three, four, five , six, seven)
local lvitems=listview_getItems(control)
local item=listitems_add(lvitems)
local subitems=listitem_getSubItems(item)
listitem_setCaption(item,level)
beginUpdate() <-----------------------begin here?
strings_add(subitems, one)
strings_add(subitems, two)
strings_add(subitems, three)
strings_add(subitems, four)
strings_add(subitems, five)
strings_add(subitems, six)
strings_add(subitems, seven)
stopUpdate() <---------------------- stop here?
end
|
Or do you mean to use them before the loop and after the loop?
_________________
**************
A simple example is better then ten links. |
|
Back to top |
|
|
Dark Byte Site Admin Reputation: 458
Joined: 09 May 2003 Posts: 25296 Location: The netherlands
|
Posted: Mon Mar 06, 2017 11:04 am Post subject: |
|
|
before and after the loop
e.g before calling the loop that calls addLevelItem call control.beginUpdate() and after the loop call control.endUpdate()
example:
Code: |
function addLevelItem(control, level, one, two, three, four, five , six, seven)
local item=control.add()
item.caption=level
item.subitems.add(one)
item.subitems.add(two)
item.subitems.add(three)
item.subitems.add(four)
item.subitems.add(five)
item.subitems.add(six)
item.subitems.add(seven)
end
UDF1.ListView1.beginUpdate()
for i=1,200 do
addLevelItem(UDF1.Listview,'aaa','bbb','ccc','ddd','eee','fff','ggg','hhh')
end
UDF1.ListView1.endUpdate()
|
Alternatively, if it is a REALLY big amount of data, try OwnerData=true and then set ListView.Items.Count to the amount of items there are, and give it an OnData event where you fill in the entry based on the index it's at
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
Back to top |
|
|
Dr.Disrespect Grandmaster Cheater Reputation: 3
Joined: 17 Feb 2016 Posts: 526
|
Posted: Mon Mar 06, 2017 11:19 am Post subject: |
|
|
Dark Byte wrote: | before and after the loop
e.g before calling the loop that calls addLevelItem call control.beginUpdate() and after the loop call control.endUpdate()
example:
Code: |
function addLevelItem(control, level, one, two, three, four, five , six, seven)
local item=control.add()
item.caption=level
item.subitems.add(one)
item.subitems.add(two)
item.subitems.add(three)
item.subitems.add(four)
item.subitems.add(five)
item.subitems.add(six)
item.subitems.add(seven)
end
UDF1.ListView1.beginUpdate()
for i=1,200 do
addLevelItem(UDF1.Listview,'aaa','bbb','ccc','ddd','eee','fff','ggg','hhh')
end
UDF1.ListView1.endUpdate()
|
Alternatively, if it is a REALLY big amount of data, try OwnerData=true and then set ListView.Items.Count to the amount of items there are, and give it an OnData event where you fill in the entry based on the index it's at |
Thanks for the reply. However, there are some issues in your example.
1. The addLevelItem() function returns this error message: attempt to call a nil value (field 'add').
2. So I had to use my old addlevelItem() function, and then I put beginUpdate() and endUpdate() before and after the loop as you instructed. However, the listview is empty after all the execution. No columns no nothing. Did I do something wrong?
_________________
**************
A simple example is better then ten links. |
|
Back to top |
|
|
panraven Grandmaster Cheater Reputation: 55
Joined: 01 Oct 2008 Posts: 942
|
Posted: Mon Mar 06, 2017 12:03 pm Post subject: |
|
|
You need to initialize the columns:
Code: |
...
while control.Columns.Count<= 7 do control.Columns.add().Caption = control.Columns.Count end
listitem_setCaption(item,level)
|
Columns 0 is for listitem, Columns 1-7 is for listitem's subitems. (Count will be 8 in above example)
_________________
- Retarded. |
|
Back to top |
|
|
Dr.Disrespect Grandmaster Cheater Reputation: 3
Joined: 17 Feb 2016 Posts: 526
|
Posted: Mon Mar 06, 2017 12:49 pm Post subject: |
|
|
panraven wrote: | You need to initialize the columns:
Code: |
...
while control.Columns.Count<= 7 do control.Columns.add().Caption = control.Columns.Count end
listitem_setCaption(item,level)
|
Columns 0 is for listitem, Columns 1-7 is for listitem's subitems. (Count will be 8 in above example) |
Thanks, panraven. But I still can't make begin and end update work.
_________________
**************
A simple example is better then ten links. |
|
Back to top |
|
|
panraven Grandmaster Cheater Reputation: 55
Joined: 01 Oct 2008 Posts: 942
|
Posted: Mon Mar 06, 2017 2:49 pm Post subject: |
|
|
Try replace DB's code <<UDF1.ListView1>> in your 'control', the columns should init outside the loop too.
May also set your control's Align to alClient, so that it fill your form.
Code: |
local myListView = <<your-control>>
myListView.Align = alClient
while myListView.Columns.Count<= 7 do myListView.Columns.add().Caption = myListView.Columns.Count end
myListView.beginUpdate()
for i=1,200 do
addLevelItem(myListView,'aaa','bbb','ccc','ddd','eee','fff','ggg','hhh')
end
myListView.endUpdate()
|
The beginUpdate/endUpdate may only exist in a recent ce version (6.6?).
_________________
- Retarded. |
|
Back to top |
|
|
Dr.Disrespect Grandmaster Cheater Reputation: 3
Joined: 17 Feb 2016 Posts: 526
|
Posted: Mon Mar 06, 2017 5:16 pm Post subject: |
|
|
panraven wrote: | Try replace DB's code <<UDF1.ListView1>> in your 'control', the columns should init outside the loop too.
May also set your control's Align to alClient, so that it fill your form.
Code: |
local myListView = <<your-control>>
myListView.Align = alClient
while myListView.Columns.Count<= 7 do myListView.Columns.add().Caption = myListView.Columns.Count end
myListView.beginUpdate()
for i=1,200 do
addLevelItem(myListView,'aaa','bbb','ccc','ddd','eee','fff','ggg','hhh')
end
myListView.endUpdate()
|
The beginUpdate/endUpdate may only exist in a recent ce version (6.6?). |
Thanks, I did replace the listview variable in DB's example, but I did not set the Align property. I will give it a try when I get home.
_________________
**************
A simple example is better then ten links. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|