OSLib File Basics
Dave Gardner (8786) 27 posts |
Hi all I’m working on code to read files from file system into memory, and write memory to files. There are a fair few options in osfile_ and I was wondering if anyone had any examples of this I could look at which might be faster than trying to work out the best option via trial/error. Thanks Dave |
Alan Adams (2486) 1149 posts |
I’ve just done something like this. I used OS_File 10 to save a block of memory to file, and OS_File 16 to load it. These two take a single parameter for the file, so it’s a full file path and name. No messing with path lists or wildcards. Hope that helps. |
Dave Gardner (8786) 27 posts |
Yes thank you. This led me to the relevant chapter in my PRM as well :) I’m still not clear about how memory allocation works. My untested working assumption is that I have to allocate enough memory to hold the contents of the file and provide the address of this buffer on read. Which I assume means I have to stat the file to work out how big it is. |
Alan Adams (2486) 1149 posts |
That will be OS_File 17, which returns the length in R4. I’d allow a small margin to that. |
GavinWraith (26) 1563 posts |
Yes, OS_File 16 and 17 work together. Here is how to convert a pathname to its contents, as a string, with Lua: BASIC is practically identical except that the DIMming of the buffer should not be inside the function.
|