[Gambas-user] Speaking of optimizations

Cedron Dawg cedron at exede.net
Sun Mar 17 19:01:26 CET 2019


I just found out about the .Max property of arrays, saving having to do a .Count - 1.  

I like it, but the name is a little confusing to me, I thought it would mean MaxValue, not MaxIndex.  No I can't think of a better short word.  "Top" is misleading, so is "Limit".

My real question is a performance related one.  Given:

        Dim a As New String[100]
        Dim i, m As Integer
        .
        .        
        m = a.Max
        For i = 0 To m
          ...
        Next
        .
        .        
        For i = 0 To a.Max
          ...
        Next
        
Does the first loop give any performance advantage over the second one?  Or does the compiler recognize that "a" won't change size in the loop and implement the first form under the covers?


More information about the User mailing list