How to save information fast!

I need to save about 90,000 elements of information really fast. I know this is probley imposible! But I am open to other ways. Right now I am using a string for each 300 sets.

But what am I trying to save? Ok I am makeing a RPG... And I want the map to be about 300 by 300. Each tile will have a number. I have tried to use integers like this
dim map(300,300)   but this is too slow to save. Then I tried to make a string with one row of the map like this
dim map$(300) But even saveing 300 strings takes too long! So I am stuck. If you can please help me I would be very greatfull. If you don't under stand what the heck I was talking about don't worry All I need is a way to save information fast. That's all. Thanks!
testing38Asked:
Who is Participating?
 
steve06Connect With a Mentor Commented:
Well,

If you really want to give your points to someone, I propose myself <;-)

I was the first one to make a constructive comment, based on the Put statement that you are now using.

Best regards,

Steve.
0
 
dabelleiCommented:
Post your code i could look at it.

You want to save in wich format txt, in database...
0
 
steve06Commented:
A fast way to save information is to use the Put statement, like in the code below:

Private Sub Command1_Click()

    Dim t(1 To 15000) As Integer
    Dim i As Long
    Dim j As Long
   
                          ' Len must be < 32767 ... too bad!
                          ' so we will have to write many times
    Open "d:\data\temp2\ttt.txt" For Binary As #1 Len = 30000
   
    For i = 1 To 6
        For j = 1 To 15000
                      ' Put here your code calculating the values    
            t(i) = i / 3
        Next j
                ' the next statement writes 30,000 bytes at a time
        Put #1, , t()
       
    Next i
   
    Close #1
   
End Sub


Steve.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
AnswerTheManCommented:
why the speed is so importamnt here, if i may ask ?
0
 
pogletreeCommented:
If you are creating a "map" why not save only "valid" informatiom.  You don't need to save the "background" if it hasn't changed.
0
 
TheAnswerManCommented:
You do know that Dim Map(300,300) gets you 90000 Variants? and not integers?
0
 
TheAnswerManCommented:
I know that referencing a single row is faster then a matrix..
so you would be better doing Dim Map(90000) as integer rather than
Dim Map(300,300) as integer

Post us some code so we can see what you are doing.

0
 
testing38Author Commented:
TheAnswerMan : I do know that dim map(300,300) is a varant. I omited the as integer by mistake.

pogletree : I want to load the entire map. Not just the changes. I'm sorry... I guess it does not have to save fast but it has to load fast. Sorry for the mixup. I am working on the map editor now and I guess I though loading and saveing might take the same amount of time.

AnswerTheMan: For saveing the map speed is not importaint... But for loading the maps it is. If maps are slow to load there will be a wait time. I want to avoid this wait time.

dabellei : My code is simple. This is a valid example of the code.

dim map(300,300) as integer
open "C:\test.txt" for output as #1

for x = 1 to 300
for y = 1 to 300
print #1, map(x,y)
next y
next x

close #1

This makes a very big .txt file but it is the only way I know how to do it. I am looking into put as we speak.

I hope this answers every ones questions. Thanks for the responces.
0
 
amebaCommented:
What is the range of possible values for your integer? Is it 0-256 or less?
You need all the optimization you can get for this size.
0
 
testing38Author Commented:
ameba: Well... I don't really want to limit my self to 257 tiles... In fact I know I don't. And by changing dim map(300,300) as integer to dim map(300,300) as byte would make this so.

steve06:I am working with your code a little and I found it to save farley fast... But how do I retreve the info. I know I use get well I think I do. Could you post the retrevil code for the code you posted before? Thanks.

What saves faster? a text file or a database file? I would try to learn more about data base if it would help me.
0
 
TheAnswerManCommented:
You'd probably be better off storing that in a table.. then you can just update the parts of the MAp that you know changed.. instead of possibly setting values of the grid = to the same values.  
this will make it very fast.  It also means you can get pieces of the map you need.. instead of having to load all 90000..
<you may want to .. i dont know your code>  but you can load say.. the bottom right corner ver fast.. where whith the textfile.. you have to Load EVERTHING to see it.
0
 
testing38Author Commented:
This may work TheAnswerMan but I don't know how to use tables. Most importaintley I don't know how to save them...
0
 
amebaCommented:
Is this why this is called "Experts Exchange"?
Experts talking to experts?
0
 
deightonCommented:
here is some code using memo fields in a database you'll need to create


REM WRITE INTEGERS TO DB as MEMO FIELDS COMMA SEPARATED

    Dim x(300, 300) As Integer
   
    Dim db As Database
   

   
    Dim rs As Recordset
   
    Dim sTemp As String
   
    Dim a As Long, b As Long
   
  Rem YOU WILL NOT NEED THE NEXT 4 LINES
 
 
    For a = 1 To 300                      'Fill a sample array with values
    For b = 1 To 300
   
        x(a, b) = Int(Rnd * 30000)
       
    Next b, a
   
    MsgBox "start"
   
    Set db = Workspaces(0).OpenDatabase("c:\temp\temp.mdb")    'make yourself a datbase
   
    db.Execute ("DELETE * from memo")     'make a table in the datbase called memo
   
    Set rs = db.OpenRecordset("memo", dbOpenTable)
   
    For a = 1 To 300
   
        sTemp = ""
   
        For b = 1 To 300
       
            sTemp = sTemp + CStr(x(a, b)) + ","
           
        Next
       
        rs.AddNew
       
        rs!txtMemo = sTemp        'your datbase fields are txtMemo type MEMO
        rs!iCounter = a           'this is a long integer field.  MAKE IT AN INDEX
       
        rs.Update
                       
   
    Next a
   
    rs.Close
    db.Close
   
    MsgBox "end"


*************************************

REM CODE TO READ BACK INTEGERS

   
Dim db As Database
    Dim rs As Recordset
   
    Dim sTemp As String, sTemp2 As String
   
    Dim a As Integer, b As Integer, iPos As Long
   
    Dim x(300, 300) As Integer    ' a sample array to retrieve the values to.
   
   
    Set db = Workspaces(0).OpenDatabase("c:\temp\temp.mdb")
    Set rs = db.OpenRecordset("memo", dbOpenTable)
   
    rs.Index = "iCounter"       'define icounter as an index in your .mdb
   
       
    For a = 1 To 300
   
        sTemp = rs!txtMemo
        q = rs!iCounter
                   
        iPos = 1
        For b = 1 To 300
           
            sTemp2 = ""
       
            While Mid(sTemp, iPos, 1) <> ","
           

                sTemp2 = sTemp2 + Mid(sTemp, iPos, 1)
                iPos = iPos + 1
               
            Wend
            iPos = iPos + 1
           
            x(a, b) = Val(sTemp2)
           
        Next
       
        rs.MoveNext
       
    Next
   
   
    rs.Close
    db.Close
   
           
       
           
           
   
   
   
   
0
 
amebaCommented:
Proposed answer looks nice and complete, but forget 2 dimensional arrays - use only 1 dimensional array (already suggested twice)
0
 
deightonCommented:
I see no reason to avoid two d arrays - the problem really is the transfer of data to the file, not its internal manipulation within the PC memory.
0
 
amebaCommented:
It is easy to measure time. We have Gettickcount API.
Dim tim0 as long, tim1 as long, tim2 as long
' start
tim0=gettickcount
' etc.
If you have sample, can you compare and report difference?

0
 
testing38Author Commented:
Ok... lets slow down here. Most of you are probabaly way above me here. I know I'm not the best programer by far but I am missing something here. I'm even more comfused then when I started. Right now... with my own experementing I have gotten put and get to work in a program. I know all you guys are thinking "stupid..." , well like I said I'm not the best programer. Every one has to start somewhere. I guess I will have to go find a book on VB databases. That should not be hard... But if a data base file wont load any faster then a text file it don't pay for me to wast my time now. Thanks to all who helped. If any one else has any more sujestions that I will UNDERSTAND please post them for I have 200 points to give to someone...
0
 
deightonCommented:
Hi,

A question.  Which version of VB are you using and what edition is it?  Does itm include 'data manager' under which you can create databases.

Theres nothing wrong with your code by the way, I certainly don't think your stupid!

I can't guarantee that the database method would be faster!
0
 
testing38Author Commented:
I'm using Visual Basic 5.0 Pro. edition
0
 
testing38Author Commented:
You are right! I am using put. Thanks for responding... I think experts exchange should make it so  some points could be given to other people. But oh well. Thanks to all who helped!!!!!!
0
All Courses

From novice to tech pro — start learning today.