On 17-May-07, at 9:47 AM, Daniel Stenning wrote:

> Maybe you could do the test:
>
> dim foo(1048576) as Integer
> dim U as Integer = UBound(foo)
> Dim c as integer
>
> // time ubound on full array
> for i as Integer = 0 to U
>  C = UBound(foo)
> next
>
> Redim foo(-1)
>
> // time ubound on empty array
> for i as Integer = 0 to U
>  C = UBound(foo)
> next
>
>
> This test would verify once for all whether the time taken to do  
> UBOUND
> varies according to the number of elements
>
> ( my strong hunch would be that it makes no difference since  
> internally RB
> is just checking an internal size variable )

It may be checking a property

However, doing
        
        for i as Integer = 0 to Ubound(aarray)
        next

is a known slow down, hence why you should do

        dim U as Integer = UBound(foo)

        for i as Integer = 0 to U
        next

The other issue, if you tried my little loop, is that the array  
ubound CAN change in the course of the loop and so using it like

        foo.append 1

        for i as Integer = 0 to ubound(foo)
                foo.append 1
        next

will generate an infinite loop. So you can't just change the ubound  
call to lookup the value of a property once and be correct

The only way to avoid this is to do the limit check once or count  
backwards through the array so the initial value is only retrieved once



_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to