Alignment
Binary files are often aligned to certain boundaries. For example “word aligned” or “double-word aligned”. This means that, if one record only took up ten bytes and the file is “double-word aligned”, then, before the next record is written, enough bytes must be written so that the record falls evenly on a double-word boundary. The next double-word boundary after ten bytes would be twelve. So two extra bytes must be written to accommodate the alignment requirement.
The BinaryFile object accommodates alignment requirements through the align method. The align method accepts one parameter that specifies the boundary to align to. This parameter is the amount of bytes that you wish to align to at this point. For example, if you were at file position ten, and you called the align method with a value of four, you would be moved to file position twelve. Because twelve is the next even multiple of four after ten.
The align method works for both read and write operations. It is important to remember that the align method only alters the way in which data is written when it is called. Therefore, it is likely that you will call the align method just after a record has been written.












