File manipulation & speed

Blitz3D Forums/Blitz3D Beginners Area/File manipulation & speed

Valgar(Posted 2004) [#1]
Hallo to all.
A simple question.
If i open 2 files outside my main and close the same at the end of my program....if i call into my main (many many time)
the function "seekfile" "readfloat" (and others too...)i have a speed down of my program?
And if yes....i have to open the file,read the data,close the file ALL outside my main?
Thanks.


Graythe(Posted 2004) [#2]
It is generally fastest by far to treat all data as string that one reads, say, 1 mb at a time and then parse the string for discreet records/fields performing type conversions where required.

Individual read and write operations for floats will slow things down measurably.

There is indeed considerable overhead to opening and closing files. It is far faster to leave them open. There can be a drawback. Some filing operations only update the file contents during a closefile operation or when a percentage of the file buffer is reached. I seem to remember that Blitz writes data `real time` but I cannot remember for sure.

Does that help?


Valgar(Posted 2004) [#3]
I open file to read data for movements (the path points
that the enemy follow)and i use float as movements variables because i use sin cos ecc ecc to make them move.
So when the program exit i close the file also.
It's best that i read data and close the file before the main?


eBusiness(Posted 2004) [#4]
Yes it's best to read all and then close the file, just store the data in one or more arrays. In this case I guess that reading speed is not really an issue, so just read your values with the readfloat function.


Valgar(Posted 2004) [#5]
I think that i have to use two array to store the data...because in my "create_alien" function i use to modify the x and y value accordingly to the path that i previously read from file...it's why i lay the file open.
I also noticed that with 20 or more enemy onscreen my speed comes down to a crawl....it's because i use floats for movements or because i use many sin cos ecc ecc?


eBusiness(Posted 2004) [#6]
Or because your graphics card can't cope with that much, usual explaination ;)