11.07.2015 Views

Advanced Programming Guide

Advanced Programming Guide

Advanced Programming Guide

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Buffered Files:4.2 File Types and Modes • 161• When buffering a lot of I/O, buffered file operations are usually faster.• Maple collects characters in a buffer and writes them to a file whenthe buffer is full or the file is closed. (Changes made in Maple maynot appear on disk until later.)• In general, you should use buffered files. They are used by defaultwith most I/O library commands.Raw Files:• Raw files are useful when examining the properties of the underlyingoperating system, such as the block size on the disk.Identifiers Commands that provide information about I/O status usethe identifiers STREAM and RAW to indicate buffered and unbuffered files,respectively.Text Files versus Binary FilesMany operating systems, including DOS/Windows and the Macintoshoperating system, distinguish between files containing sequences of characters(text files) and files containing sequences of bytes (binary files).The distinction lies primarily in the treatment of the newline character.Other distinctions may exist on some platforms, but they are not visiblewhen using the Maple I/O library.Within Maple, the newline character, which represents ending oneline and beginning a new one, is a single character (although you cantype it as the two characters “\n” within Maple strings). The internalrepresentation of this character is the byte whose value is 10, the ASCIIlinefeed character. Many operating systems, however, represent the conceptof newline within a file using a different character, or a sequence oftwo characters. For example, DOS/Windows represents a newline withtwo consecutive bytes whose values are 13 and 10 (carriage return andline feed). The Macintosh represents a newline with the single byte withvalue 13 (carriage return).The Maple I/O library can use text files or binary files. When Maplewrites to a text file, any newline characters that it writes to the file aretranslated into the appropriate character or character sequence that theunderlying operating system uses. When Maple reads this character orcharacter sequence from a file, it translates it to the single newline character.When Maple writes to a binary file, no translation takes place; it

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!