• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

file_text_* vs buffer

quattj

Member
I have a text file that I need to parse. I've been using the file_text_* functions, which are doing what I need. But I also know the buffer* functions are newer/faster. The amount of reading I am doing is not noticeable timewise, so speed doesn't really matter. But I want to do it properly, so, a few questions:

Let's says I have a buffer "XG_ini".

With text functions,
GML:
while (!file_text_eof(XG_ini))
{
    next_line = file_text_read_string(XG_ini);
    file_text_readln(XG_ini);
}
I extract strings and numbers I need from next_line.

However, I'm not sure how to do the same with buffers. I've done binary buffers where I am reading through the entire buffer from start to end, and I know the sizes of all my data beforehand so can select the right size read or buffer spot when needed. I don't know how to do this with a text file, especially when it comes to the EOF marker, and new line/carriage returns.

I tried using XG_ini = buffer_load(etc...
but using
next_line = buffer_read(XG_ini, buffer_string);
or
next_line = buffer_read(XG_ini, buffer_text);

both read the whole entire file in to the string. Super opposite of useful. :/ And doing a byte by byte read would defeat the purpose of using buffers in the first place.
 
Last edited:

kburkhart84

Firehammer Games
In my opinion, with text files, unless you are having performance issues, you are likely just fine doing it the old way as you are doing it now. If you were using binary stuff, it would make more sense to me to switch to buffers.

That said, the buffer version will still be faster as far as reading the file, but you would still have to look for that "end of line" byte.
 

FrostyCat

Redemption Seeker
Buffers displaced file_bin_* functions, not file_text_* functions. Doing it with buffers is possible, but you will then be reading byte-by-byte sniffing for the LF at GML speed, which is strictly worse from both a convenience and speed perspective. It just isn't worth it.

If you want to keep doing it properly, continue using file_text_* functions the way you used to.
 

quattj

Member
Buffers displaced file_bin_* functions, not file_text_* functions. Doing it with buffers is possible, but you will then be reading byte-by-byte sniffing for the LF at GML speed, which is strictly worse from both a convenience and speed perspective. It just isn't worth it.

If you want to keep doing it properly, continue using file_text_* functions the way you used to.
Ahhh, okay, good. the more I tried to use buffers for it, the more complicated it kept getting :p

That being said, I was unaware of the ini_* functions, and the files I am reading in just happen to follow the exact format that the ini_* functions use, so I am going to give those a shot. My main issue arose because some of the files I'm reading have carriage return/line feed, and some only have ... umm, one of those. I think the ini_* functions might help out with that.
 
Top