MSGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### Precalculated array

• Follow

```I have an array which stores values of precalculate results at certain
positions (x,y):

Theoretical, it would look like this:

Dim sngArr(200000,200000) as single
For example sng(1,1) would be 0.003923

Of course this is not possible due to the memory capacity.
Any wild ideas how you would do that?
Any input is welcome!

```
 0

```"Anders Jorgenson" <a.jorg@lycos.com> wrote in message
news:%23\$Uc5mKULHA.5432@TK2MSFTNGP05.phx.gbl...
>I have an array which stores values of precalculate results at certain
>positions (x,y):
>
> Theoretical, it would look like this:
>
> Dim sngArr(200000,200000) as single
> For example sng(1,1) would be 0.003923
>
> Of course this is not possible due to the memory capacity.
> Any wild ideas how you would do that?
> Any input is welcome!

Put the points in an array, then loop through it. Example air code:

Private Type TMyPoints
x As Long
y As Long
Value As Single
End Type

Private MyPoints() As TMyPoints
Private MyPointsCount As Long

ReDim MyPoints(1 To 10000)  ' Initial size
End Sub

Private Sub AddPoint(x As Long, y As Long, Value As Single)

If MyPointsCount >= UBound(MyPoints) Then
' Time to enlarge the array
ReDim Preserve MyPoints(1 To UBound(MyPoints) + 10000)
End If

MyPointsCount = MyPointsCount + 1
MyPoints(MyPointsCount).x = x
MyPoints(MyPointsCount).y = y
MyPoints(MyPointsCount).Value = Value
End Sub

Private Function GetPoint(x As Long, y As Long, ByRef bNotFound As Boolean)
As Single
Dim i As Long

For i = 1 To MyPointsCount
If x = MyPoints(i).x And y = MyPoints(i).y Then
GetPoint = MyPoints(i).Value
Exit Function
End If
Next
If i = MyPointsCount + 1 Then
bNotFound = True
End If
End Sub

```
 0

```Another approach is to use a collection, and use x*y as a key. This is
probably faster if you have large number of items, but uses more memory.

```
 0

```On Sep 10, 5:32=A0pm, Anders Jorgenson <a.j...@lycos.com> wrote:
> I have an array which stores values of precalculate results at certain
> positions (x,y):
>
> Theoretical, it would look like this:
>
> Dim sngArr(200000,200000) as single
> For example sng(1,1) would be 0.003923
>
> Of course this is not possible due to the memory capacity.
> Any wild ideas how you would do that?
> Any input is welcome!

http://www.vb-helper.com/tut2.htm

powerful data structures that can save you memory in your Visual Basic
and VBA applications. "
```
 0

```"Nobody" <nobody@nobody.com> wrote in message
news:i6cjvb\$nhr\$1@speranza.aioe.org...

> Put the points in an array, then loop through it. Example air code:
> Private Type TMyPoints
>    x As Long
>    y As Long
>    Value As Single
> End Type
> Private MyPoints() As TMyPoints
> Private MyPointsCount As Long
>    ReDim MyPoints(1 To 10000)  ' Initial size
> End Sub

I think you migth have missed this line in the OP's post ;-)

Dim sngArr(200000,200000) as single

He's going to need to have data of that size on disk.

Mike

```
 0

```On 10/09/2010 08:17, Mike Williams wrote:
> "Nobody" <nobody@nobody.com> wrote in message
> news:i6cjvb\$nhr\$1@speranza.aioe.org...
>
>> Put the points in an array, then loop through it. Example air code:
>> Private Type TMyPoints
>> x As Long
>> y As Long
>> Value As Single
>> End Type
>> Private MyPoints() As TMyPoints
>> Private MyPointsCount As Long
>> ReDim MyPoints(1 To 10000) ' Initial size
>> End Sub
>
> I think you migth have missed this line in the OP's post ;-)
>
> Dim sngArr(200000,200000) as single
>
> He's going to need to have data of that size on disk.

I think people are more likely to have 149GB of disk space than memory :p

--
Dee Earley (dee.earley@icode.co.uk)
i-Catcher Development Team

iCode Systems

(Replies direct to my email address will be ignored.
```
 0

```"Dee Earley" <dee.earley@icode.co.uk> wrote in message
news:%235AkYFMULHA.4980@TK2MSFTNGP04.phx.gbl...
>> [The OP said]
>> Dim sngArr(200000,200000) as single
>> [Mike Williams said] He's going to need to have data of that size on
>> disk.
>
> I think people are more likely to have 149GB of disk space than memory :p

Exactly, which is why I said he needs to have it on disk. Mind you, having
said that, I can remember the time when I would have said you're not gonna'
fit data of that huge size (8KB) in memory! Who knows what the future will
bring ;-)

Mike

```
 0

```On 10/09/2010 09:47, Mike Williams wrote:
> "Dee Earley" <dee.earley@icode.co.uk> wrote in message
> news:%235AkYFMULHA.4980@TK2MSFTNGP04.phx.gbl...
>>> [The OP said]
>>> Dim sngArr(200000,200000) as single
>>> [Mike Williams said] He's going to need to have data of that size on
>>> disk.
>>
>> I think people are more likely to have 149GB of disk space than memory :p
>
> Exactly, which is why I said he needs to have it on disk. Mind you,
> having said that, I can remember the time when I would have said you're
> not gonna' fit data of that huge size (8KB) in memory! Who knows what
> the future will bring ;-)

You want one of these then :)
http://www.oracle.com/us/products/servers-storage/servers/x86/sun-fire-x4800-server-077287.html

--
Dee Earley (dee.earley@icode.co.uk)
i-Catcher Development Team

iCode Systems

(Replies direct to my email address will be ignored.
```
 0

```"Anders Jorgenson" <a.jorg@lycos.com> wrote
> I have an array which stores values of precalculate results at certain
> positions (x,y):
>
> Theoretical, it would look like this:
>
> Dim sngArr(200000,200000) as single
> For example sng(1,1) would be 0.003923
>
> Of course this is not possible due to the memory capacity.
> Any wild ideas how you would do that?
> Any input is welcome!

"At certain positions" would tend to indicate not all positions
need to be represented.  If you only need a few thousand
points to be represented, then use the sparse array.

If you need several million points to be present,
then look at managing the data in disk files....

LFS

```
 0

8 Replies
457 Views