11-21-2023, 06:41 PM
File I/O like routines for memory loaded files.
The StringFile library can be used for dealing with files that are completely loaded in memory. Since it uses QB64 strings as a backing buffer, no explicit memory management (i.e. freeing) is required. No need to worry about opening, closing, or freeing anything. Everything is nicely cleaned up when it goes out of scope.
API List:
I actually have a C version of this, but I made a pure QB64 version for something that I am working on. Sorry, there is no demo for this one. There is some test code in StringFile.bas. Most of it is very simple and straightforward.
Notes:
1. Unlike QB64 file I/O stuff, StringFile is 0 based. Meaning the first byte in the file is at position 0. This helps a lot when porting over code from languages like C.
Stuff like
can be replaced by
2. StringFile is optimized for little-endian. So, if you are loading big-endian stuff, ensure you do the necessary byte swaps.
3. Just because the whole file is in memory, you are not allowed to be careless. StringFile will yell at you (read throw errors) if you do stuff like reading past the end of the file or positioning the cursor to a non-existent location.
The StringFile library can be used for dealing with files that are completely loaded in memory. Since it uses QB64 strings as a backing buffer, no explicit memory management (i.e. freeing) is required. No need to worry about opening, closing, or freeing anything. Everything is nicely cleaned up when it goes out of scope.
API List:
I actually have a C version of this, but I made a pure QB64 version for something that I am working on. Sorry, there is no demo for this one. There is some test code in StringFile.bas. Most of it is very simple and straightforward.
Notes:
1. Unlike QB64 file I/O stuff, StringFile is 0 based. Meaning the first byte in the file is at position 0. This helps a lot when porting over code from languages like C.
Stuff like
Code: (Select All)
byte = fgetc(f);
Code: (Select All)
byte = StringFile_ReadByte(sf)
2. StringFile is optimized for little-endian. So, if you are loading big-endian stuff, ensure you do the necessary byte swaps.
3. Just because the whole file is in memory, you are not allowed to be careless. StringFile will yell at you (read throw errors) if you do stuff like reading past the end of the file or positioning the cursor to a non-existent location.