English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

if i hav a record of 30 bytes and i wanna store it in a disk sectored with 512 bytes. why will i wanna pad it to 32 bytes

2006-10-18 13:34:37 · 3 answers · asked by jasmine 3 in Computers & Internet Programming & Design

3 answers

There are several reasons why you might want to pad records. In the specific case that you give, where you have a record with a size of 30 bytes and you are wondering why you would want to pad it to 32 bytes, there is one glaring reason.

This primary reason is related to the sector size on your disk, as you suggest. If you have a record size of 32 instead of 30 bytes, an integral (whole) number of records will fit in a sector. Exactly 16 records will fit if the record is padded up to 32 bytes. If you leave the record size at 30 bytes, 17 records will fit in a sector, with another 2 bytes of the 18th record. Breaking records on the sector boundary will mean that the disk will have to read two whole sectors when trying to get the 18th record. This is inefficient.

Another reason you might want to pad a record is for future expansion. If you pad your structures, you are essentially saving room for future additions to the structure while preserving at least the possibility of backward compatibility. If you pad your structure with another 2 bytes, you could add a short integer or two characters (or two Booleans, etc.) to your structure and still be able to read old data into new records. You would still have to add logic for handling the zeroed fields, etc., but you wouldn't have to change your file format.

I hope that this helps!

2006-10-18 16:32:08 · answer #1 · answered by codewriterdavid 3 · 1 0

What computer language are you programming with?
Your question seems strange to me. Writing directly to sectors is something that your hard drive/floppy drive disk controller does.
Why are you concerned about sector alignment?

Maybe you should post your code. If you want to pad data, you just subtract what you have from 512 and then add that amount of zero bytes to your file write data buffer.

2006-10-18 20:45:58 · answer #2 · answered by Balk 6 · 0 0

Wow is that an obsolete question!

Back when it mattered, you'd want to pad your record out so it would divide evenly into your storage medium's physical block size. In your example above, you wouldn't want a record to span two sectors; it'd be much more efficient for retrieval if no record spanned two sectors, right?

2006-10-18 20:38:57 · answer #3 · answered by Anonymous · 0 0

fedest.com, questions and answers