See, when you use GML, how do you read an entire file's contents? The fastest way, sadly, is line-by-line, using GM's already-slow file I/O functionality.
This DLL uses C++'s much-faster I/O functionality, and reads the entire file at once. Hence why it's so much faster .
Here's the link: http://h1.ripway.com...a4/ReadFile.zip
It has 2 functions:
file_read_init() - Simply initializes the DLL. Call this ONCE before calling the other function.
file_get_contents(file) - Reads and returns the entire contents of "file". But much more quickly than GML would
Included in the ZIP are 5 files:
1) The GML file. This contains the 2 scripts above, so you can put them in any of your own games/programs.
2) The DLL. The most important file .
3) The GMK example. This includes an extra script which simply reads the test file the GML way, timing it, then reads it the DLL way, timing it, then returns a few forms of the time difference for you to see.
4) The GM6 version of the example, for those of you who don't have GM7. The DLL works the same no matter which version of GM you use.
5) The TESTING.txt file. This is just a (very repetitive) 2.5MB text file for the example to read. It's just to show you that the DLL is very useful for large files.
NOTE 1: The examples run the GML version before the DLL version, to show the time difference. Since it does start with GML, and it is using a 2.5MB file, it could take a long time. It uses a WHILE loop to make it run as fast as possible, but that also means that once the reading begins, you can't close the program until it's done or you press CTRL+ALT+DEL. Be warned: Don't run the example unless you have the patience to wait for the results.
Come to think of it, that long "pause-time" is actually the reason this DLL was made !
Note 2: This DLL is basically useless on small files, since GML can read smaller files fairly quickly. However, on larger files (like files over 1MB) the DLL becomes much faster and much more needed. I don't know where the "cutoff" point is when the DLL becomes useful compared to GML, but I suppose it's somewhere around 1MB, and that it also depends on the computer. I suggest using the DLL in any case, since some computers may be slower than others, so you'll need all the speed you can get .
Make sure you look at the code in the examples so that you know: They're not biased either way. They are completely objective, and simply record times. Don't think I rigged it to show a faster time for the DLL .
*EDIT* Oh, I almost left without telling you guys about the error codes.
Should an error occur with the DLL, it will return an error string instead of the file's contents. This will be one of the following:
"ERROR: Could not open file." - This is self-explanatory, and may be caused by a few things, such as the file being open somewhere else.
"ERROR: Could not create buffer." - This means the memory buffer couldn't be created. I don't know much about buffers, but I believe this should only occur if you don't have enough RAM left to read the size of the file. So make sure if you're reading a 700MB file that you have at least 700MB of RAM left, or you'll get this message. On most modern computers, with standard file sizes, this shouldn't be a problem, and you probably won't get this error very often, if at all.
"ERROR: Could not read from file." - I don't think this will ever happen, but I put the error string in there just in case. Basically, it means the file was opened and the buffer was created, but for whatever reason the contents of the file could not be read. Again, I don't think this will ever happen.
Edited by IceMetalPunk, 06 July 2007 - 07:21 AM.