File functions - Which to use
I've been going throught the file functions in the wiki and the forum, and it's seems there's some contradiction in their use since the wiki says some functions are deprecated, but they are still mentioned here in the forums. So, could anyone please make a little list with the ones i should use? I'd really appreciate it
|
Re: File functions - Which to use
fopen/fclose/fgets/fputs and the like are the "ideal" functions to use, but they're a bit harder to use (unless you've had prior experience with them in C) than read_file/write_file.
read_file especially is a very expensive native when used in a medium to large sized file. It's fine if used only for a couple of lines, but ideally you should use fgets() (and, obviously fopen()/fclose()) instead for anything large or speed-critical. |
Re: File functions - Which to use
Great! Thanks for the speedy reply.
Another quick question: From what i've read, I assume the difference between fgets/fputs and read_file/write_file is that while the first ones have a c like behaviour, the write_file, because it offers "line operations", it "moves" the file everytime a line has its lenght modified, or a line is added somewhere other than the EOF, and read_file has to do a sequential search counting /n to reach a line number (hence the "expensiveness"). Ok then, since I need a fixed-size record file I was hoping i could use a function like C's fread, but i guess i'll have to abuse fgets. Again, thank you for your help! |
Re: File functions - Which to use
fread exists (I just didn't comment about it), look in amxmodx/scripting/include/file.inc
I don't think it's well documented in the funcwiki though. And yeah, for each read_file, core opens the file, scans to the line (a bunch of fgets()), byrefs the requested line and closes the file. write_file is similar (although write_file with a -1 line (append) is fast). |
Re: File functions - Which to use
Yes, i saw it and fread_blocks too, but there was a comment for fwrite saying " This function doesn't work anymore in higher versions then amxmodx 1.5", that made me think the whole "fwrite/read function family" was not working. My bad.
So (to sum up): fread/fwrite fread_blocks/fwrite_blocks are acceptable? |
Re: File functions - Which to use
Just a bit more info to make things even a bit more clear, since i agree that file routines a bit confusing because of some inconsistency.
I've made a diff between Function Listing for Core::file.inc and current file.cpp and that's what i see: build_pathname - in cpp, not in the wiki The below functions in the wiki, but not in cpp anymore: fflush |
Re: File functions - Which to use
Great, thank you both!
|
| All times are GMT -4. The time now is 00:36. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.