Programming Do's and Don'ts


Clearly, CD-ROM is a somewhat fragile and imperfect storage medium. But there are things a programmer can do, and avoid doing, to reduce problems, increase data integrity, and increase data rates. This section provides some advice, looking at the following topics:

Making Assumptions about Data Delivery Rates

Don't assume a certain data delivery rate from the drive to a data buffer.

Do check the real error code in the IOReq structure before reading from a data buffer to make sure that good data is in the buffer:

err = DoIO(ioReqItem, &ioInfo);
if (err < 0 || (err = ioReq->io_Error) < 0)
    {
    printf(Error getting status:");
    PrintfSysErr(err);
    }

Handling Data Delays

Don't abort out of a task if that task can't read data from a data buffer, or if the task does not receive data as fast as it expects.

Do handle data delays gracefully. For example, an application should not crash if there is a data delay; it should be designed to minimize the problem and glitch in the video stream and continue when it receives the data it needs.

Alternating File Reads

Don't alternate reads, rapidly, between two or more files. This almost always require seeking, which imposes a fairly drastic delay (see section above).

Do consider combining data from many small files (e.g., sound effects) into one file, with a compact table-of-contents at the beginning of the file. At the very least, if you must have two or more files, make sure the files are physically as close to each other on the disc as possible.

Testing Performance

Don't assume that the program's performance when run in development mode (from /remote) is the same as when it's run on a CD-ROM, even if you are running with CD Emulation in Special Mode in the Debugger.

Do test actual performance on a physical CD-ROM disc, in all currently-available 3DO players.

Other Things You Should Do