list.count() and speed

BlitzMax Forums/BlitzMax Beginners Area/list.count() and speed

Hi, at the moment I am storing a variable which keeps track of how many objects are in my list. I would rather just use the list.count() method, but wondered if accessing this method would be significantly slower then updating a seperate varaible which tracks how many objects are in the list? (possibly negligable but I just wanted to check). I wouldnt be accessing the .count() method every frame.....or is this something too small to be concerned about?

Only if you had thousands of objects in said list, or needed to get that number thousands of times a frame would it amount to anything worth concerning yourself about.

Ant,
As sswift said.
However, you can check this sort of thing easily yourself...
Type ttest
  Global mylist=CreateList()
End Type
For x = 1 To 10000
  my:ttest = New ttest
  ListAddLast ttest.mylist,my
Next
start=MilliSecs()
Print CountList(ttest.mylist)
Print MilliSecs()-start


Plus you should also take into account the size of the type

ie
10,000,000 types with 2 variables take 198 ms

10,000,000 types with 12 variables take 619 ms

so as types increase in size the count is slowed also

using field x[12] will make the count speed up some
ie a field array of five will make it faster than 5 fields
549 ms

Hmmm.. few quick tests don't show a difference in speed with more variables in the type.
Listcount seems to counts the number of links on a list.
How would that be affected by the size of object?

I'm pretty sure Duckstabo is mistaken. The size of the elements in the list itself is fixed. There is one pointer which points to your type. There is no reason for the count function to ever look at your type. It should only look at the elements in the list, and ignore that pointer to your type.

I guess the size of the object becomes relevant when you have a limited amount of physical memory.