Huge Arrays
Huge Arrays
Huge Arrays
Huge Arrays
Huge Arrays
Huge Arrays Huge Arrays Huge Arrays Huge Arrays Huge Arrays Huge Arrays Huge Arrays Huge Arrays
Huge Arrays Huge Arrays
Huge Arrays
Go Back  Xtreme Visual Basic Talk > > > Huge Arrays


Reply
 
Thread Tools Display Modes
  #1  
Old 09-21-2016, 09:26 AM
mms mms is offline
Ultimate Contributor
 
Join Date: Jul 2002
Location: Hamilton, Ontario
Posts: 1,855
Default Huge Arrays


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?

Form code:
Code:
Option Explicit


Private Sub Form_Load()
    Command1.Caption = "Save"
End Sub


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
        Next 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"
    
        MsgBox obj(500000).objectType
        
    ' Test copying the loaded array to another array
    
        Dim temp() As GridObject
        temp = obj
        
        MsgBox "Array copied to temp array."
        
        MsgBox temp(750000).objectType
    
    ' Write the memory array to disk
        
        Screen.MousePointer = vbHourglass
        
        Dim sFile As String
        sFile = "SavedFile.txt"
        
        Kill sFile
    
        DoEvents    'try to get screen mouse pinter to display
    
        Open sFile For Binary Access Write Lock Read Write As #1
    
            Put #1, , obj
    
        Close #1
        
        Screen.MousePointer = vbDefault
    
        MsgBox "Array saved to disk."
    
End Sub
Module code:
Code:
Option Explicit


Public Type POINTF
    X As Single
    Y As Single
End Type

Public Type GridPosition
    col As Long
    row As Long
End Type

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
End Type


Public obj() As GridObject
Public numObjects As Long
Reply With Quote
Reply

Tags
array, msgbox, numobjects, type, integer, size, public, temp, obj, sfile, code, write, gridobject, dim, memory, disk, string, arrays, pointf, lenobj0, bytes, huge, test, formatlenobj0, total


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Huge Arrays
Huge Arrays
Huge Arrays Huge Arrays
Huge Arrays
Huge Arrays
Huge Arrays Huge Arrays Huge Arrays Huge Arrays Huge Arrays Huge Arrays Huge Arrays
Huge Arrays
Huge Arrays
 
Huge Arrays
Huge Arrays
 
-->