Solved

How to save information fast!

Posted on 1998-10-19
21
213 Views
Last Modified: 2010-04-30
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!
0
Comment
Question by:testing38
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
  • 3
  • +5
21 Comments
 
LVL 2

Expert Comment

by:dabellei
ID: 1440638
Post your code i could look at it.

You want to save in wich format txt, in database...
0
 
LVL 1

Expert Comment

by:steve06
ID: 1440639
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
 
LVL 5

Expert Comment

by:AnswerTheMan
ID: 1440640
why the speed is so importamnt here, if i may ask ?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Expert Comment

by:pogletree
ID: 1440641
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
 
LVL 3

Expert Comment

by:TheAnswerMan
ID: 1440642
You do know that Dim Map(300,300) gets you 90000 Variants? and not integers?
0
 
LVL 3

Expert Comment

by:TheAnswerMan
ID: 1440643
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
 

Author Comment

by:testing38
ID: 1440644
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
 
LVL 15

Expert Comment

by:ameba
ID: 1440645
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
 

Author Comment

by:testing38
ID: 1440646
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
 
LVL 3

Expert Comment

by:TheAnswerMan
ID: 1440647
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
 

Author Comment

by:testing38
ID: 1440648
This may work TheAnswerMan but I don't know how to use tables. Most importaintley I don't know how to save them...
0
 
LVL 15

Expert Comment

by:ameba
ID: 1440649
Is this why this is called "Experts Exchange"?
Experts talking to experts?
0
 
LVL 18

Expert Comment

by:deighton
ID: 1440650
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
 
LVL 15

Expert Comment

by:ameba
ID: 1440651
Proposed answer looks nice and complete, but forget 2 dimensional arrays - use only 1 dimensional array (already suggested twice)
0
 
LVL 18

Expert Comment

by:deighton
ID: 1440652
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
 
LVL 15

Expert Comment

by:ameba
ID: 1440653
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
 

Author Comment

by:testing38
ID: 1440654
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
 
LVL 18

Expert Comment

by:deighton
ID: 1440655
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
 

Author Comment

by:testing38
ID: 1440656
I'm using Visual Basic 5.0 Pro. edition
0
 
LVL 1

Accepted Solution

by:
steve06 earned 200 total points
ID: 1440657
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
 

Author Comment

by:testing38
ID: 1440658
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question