Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Whats the best cache methods for string arrays


Lavos
 Share

Recommended Posts

Okay I have been studying many methods to create a string array for cache files and I've seen many methods, It blew my mind all week. I just need to know which method would be better in a system.

Method Referenced by eclipse:

```

Public Tex_Floors() as string

Public Count_Floor() as long

Count_Floor = 1

Do While FileExist(App.Path & PATH_FLOORS & Count_Floor & GFX_EXT, True)

ReDim Preserve Tex_Floors(0 To Count_Floor) As String

Tex_Floors(Count_Floor) = App.Path & PATH_FLOORS & Count_Floor & GFX_EXT

Count_Floor = Count_Floor + 1

Loop

Count_Floor = Count_Floor - 1
```

V.S.

Referenced by google researches

```

Public Tex_Floors(Floor_Count) as string

Dim i as long

For i = 1 To UBound(Tex_Floors)

Tex_Floors(i) = App.Path & PATH_FLOORS & i & GFX_EXT

Next
```

Both blocks work fine, please be detailed on why you pick your answer, there is got to be a good reason in your theory or fact.

Thank you.
Link to comment
Share on other sites

The second block will execute faster:

1. The size of the array is already set.

2. It loops through and fills the array until it reaches the end of the array.

The first block:

1. Checks if the file exists first.

2. If it does, it resizes the array then places the data inside.

Although the performance isn't very significant (maybe a couple ms difference) the second block _is_ faster. The difference between the two is simply the Eclipse version doesn't know the size of the array so it sets it while loading it as in the second block already knows the size of the array.
Link to comment
Share on other sites

I did a benchmark. What I did was load an array 1,000,000 times using each method.

Block One: 906ms

Block Two: 125ms

You can clearly see that the second method loads the data faster because you aren't re-sizing the array each time because it's already set. However, you're not loading 1,000,000 files so you would hardly see a difference anyway.
Link to comment
Share on other sites

Use GetTickCount. For example:

```

Dim tick As Long, tick2 As Long

tick = GetTickCount

`tick2 = GetTickCount`
``` `Then all you do is subtract tick2 from tick and that's how much time it took for the code in `to run.``
Link to comment
Share on other sites

> Use GetTickCount. For example:
>
> ```
>
> Dim tick As Long, tick2 As Long
>
> tick = GetTickCount
>
> `tick2 = GetTickCount`
> ``` `Then all you do is subtract tick2 from tick and that's how much time it took for the code in `to run.``

``Just thought I would say that is a pretty cool idea.``
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...