## File I/O

### Single File Sm32 files

Single file SM32 files place both KEYS and DATA in the same file (INDEXED,DIRECT and MKEYED). It is possible to fill an SM32 file and get an ERROR 2 on a write. However if you give a reasonable aproximation for the # of records this will never happen. You will not get an ERROR 2 until you have more than 128 times the defined size. There is some small overhead when the size goes somewhat over twice the defined size. The following is the internals of how the space allocation works:
The file header (which becomes memory resident) has 16 alocation pointers. SM32 uses your file define to calculate an allocation size so that the data portion of your file will fit into 8 blocks of the allocation size:
Allocation Size = INT(((records * rec_size)/(8*page_size)+1))*page_size
where the SM32 page_size is 4096.
for a define of:
DIRECT "DTEST",10,1000,100,2
That would be:
INT(((1000 *100)/(8*4096)+1))*4096 = 16384
With 16 allocation pointers (16 * 16384)/100 gives room for 2621 records. When the 2622 record is written SM32 makes room for 1024 pointers copying its 16 pointers into the 1024 pointers (these pointer are not memory resident). With 1024 allocation pointers (1024 * 16384)/100 gives room for 167772 records. When the 167773 record is attempted to be written an error 2 occurs. So in this case a define of 1000 records gives an ERROR 2 on the 167773 record.

### Sm32 .SM files

If "Use a single file for SM32 files (no.SM file)" is not checked on the Disk I/O Property page then all INDEXED, DIRECT and MKEYED statements create 2 FILES. The 1st contains the HEADER and KEYS while a 2nd with a .SM extension contains all the DATA records.

### More to Come

SEE:
DIRECT SORT INDEXED MKEYED