| Posted: 12:09pm 22 Mar 2026 |
Copy link to clipboard |
 Print this post |
|
I need help understanding the MEMORY INPUT command.
I have a data file that consists of an integer header followed by any number of fixed size blocks that my program needs to write and read.
I have a type defined for the block, but since the header is just an integer, I am trying to use MEMORY INPUT to read it and MEMORY PRINT to write it. MEMORY PRINT works.
I use STRUCT SAVE and STRUCT LOAD after an appropriate SEEK to write and read the desired block and that works.
If the file consists of just the header with no blocks, such that it is only 8 bytes long, MEMORY INPUT works. However, if the file has any blocks so that the length is greater than 8, MEMORY INPUT fails with and End of File error.
OPEN "File" FOR RANDOM AS #1 LOCAL I% SEEK #1, 1 MEMORY INPUT #1, 8, PEEK(VARADDR, I%)
If I change my code and add a TYPE containing just an INTEGER, STRUCT LOAD works fine to read the header regardless of the file size.
----------------------
On a related question, what is the appropriate way to truncate a file? Currently, I'm opening it for OUTPUT, then closing it, then opening it in RANDOM. The other option I see is to use KILL and ignore the error if the file didn't already exist.
Thanks, Mark |