Original Author Paul Laughton, 2011
Page 106
De Re BASIC!
Mark and Mark Limit
Note: This is an advanced file management technique that you will rarely need to use. However, see the
note below about Out of Memory errors when reading very large files.
Every file has a mark and a mark limit. The mark is a position, and the mark limit is a size. As you read a
file, its data is copied into a buffer. The buffer starts at the mark, and its length is the mark limit. BASIC!
uses the buffer to allow you to reposition within the file. You are really repositioning within the buffer.
If you do not mark a file, then the first time you read it or set a position in it, the mark is set at position 1
and the mark limit is set to the size of the file. This allows you to position and read anywhere in the file.
The Text.position.mark and Byte.position.mark commands override the default mark and mark limit.
You can change the mark and mark limit as often as you like, but there is only one mark in a file.
You cannot set a position before the mark. If you try, the file will be positioned at the mark. You will not
be notified that the current position is different from what you requested, but you can use
Text/Byte.position.get to determine the real position. Since the default mark position is 1, you can
position anywhere if you never set a mark.
You cannot make the buffer smaller. If you want the buffer to be smaller than the file, you must execute
Text/Byte.position.mark before reading the file or setting a position. The smallest buffer size available is
8096 bytes, but it is not an error to specify a smaller number. Since the default mark limit is the file size,
you can position anywhere if you never set a mark limit.
If you read or position past the end of the buffer (more than marklimit bytes beyond the the mark), the
mark is invalid. It is an error to try to move the position backward when the mark is invalid. You will see
the error message "Invalid mark". Since the default buffer is the whole file, you will never see this error
if you never set a mark.
There is only one condition that requires you to use this command. If you open a very large file, the
default buffer size may be too large.
Reading or positioning to the end of the file may cause an Out Of
Memory
error. To avoid this error, your must use Text.position.mark to reduce the buffer size.
File Commands
File.delete <lvar>, <path_sexp>
The file or directory at <path_sexp> will be deleted, if it exists. If the file or directory did not exist before
the Delete, the <lvar> will contain zero. If the file or directory did exist and was deleted, the <lvar> will
be returned as not zero.
The default path is "<pref base drive>/rfo-basic/data/".