I'm getting an "Out of Memory" error in my program when I'm manipulating some huge arrays, so I'm starting from scratch to understand better.
A few questions on the code below:
1. Why can't I get the screen pointer to display when saving to disk?
2. Am I calculating the array size correctly?
3. I've declared objectType as a string with no size... is it always 4 bytes regardless of length?
4. How come VB doesn't complain "subscript out of range" for Len(obj(0)) when I have declared it base 1?
5. Do I have to erase these big arrays manually, or does VB take care of it when program is closed?
6. Why doesn't the temp array have to be dimensioned when I copy the obj array into it?
Private Sub Form_Load()
Command1.Caption = "Save"
Private Sub Command1_Click()
' Fill array
numObjects = 1000000
ReDim Preserve obj(1 To numObjects)
Dim i As Long
For i = 1 To numObjects
obj(i).objectType = "test" & i
obj(i).position.col = i
MsgBox "Array loaded in memory."
MsgBox "Size of 1 array item = " & Len(obj(0)) & " bytes"
MsgBox "Size of total array = " & Format((Len(obj(0)) * numObjects) / 1000 / 1000 / 1000, "#0.000") & " Gigabytes"
MsgBox "Size of total array = " & Format((Len(obj(0)) * numObjects) / 1024 / 1024 / 1024, "#0.000") & " Gigabytes"
' Test copying the loaded array to another array
Dim temp() As GridObject
temp = obj
MsgBox "Array copied to temp array."
' Write the memory array to disk
Screen.MousePointer = vbHourglass
Dim sFile As String
sFile = "SavedFile.txt"
DoEvents 'try to get screen mouse pinter to display
Open sFile For Binary Access Write Lock Read Write As #1
Put #1, , obj
Screen.MousePointer = vbDefault
MsgBox "Array saved to disk."
Public Type POINTF
X As Single
Y As Single
Public Type GridPosition
col As Long
row As Long
Public Type GridObject
objectType As String
points As POINTF
position As GridPosition
gNum As Long
pathDP As Long
pathHT As Long
oe01 As Long
oe02 As Integer
oe03 As Integer
oe04 As Integer
oe05 As Integer
associatedPoints As POINTF
code As Integer
track As Long
Public obj() As GridObject
Public numObjects As Long