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!
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()
why the speed is so importamnt here, if i may ask ?
0
The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.
One of a set of tools we're offering as a way of saying thank you for being a part of the community.
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.
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.
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...
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...
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
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
Question has a verified solution.
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
You want to save in wich format txt, in database...