Estimating File Size
You can estimate the number of pages, and therefore the number of bytes required to store a file. However, when using the formulas, consider that they only approximate file size because of the way the transactional interface dynamically manipulates pages.
*Note: The following discussion and the formulas for determining file size do not apply to files that use data compression, because the record length for those files depends on the number of repeating characters in each record.
While the formulas are based on the maximum storage required, they assume that only one task is updating or inserting records into the file at a time. File size increases if more than one task updates or inserts records into the file during simultaneous concurrent transactions.
The formulas also assume that no records have been deleted yet from the file. You can delete any number of records in the file, and the file remains the same size. The transactional interface does not deallocate the pages that were occupied by the deleted records. Rather, the transactional interface re-uses them as new records are inserted into the file (before allocating new pages).
If the final outcome of your calculations contains a fractional value, round the number to the next highest whole number.
Formula and Derivative Steps
The following formula is use to calculate the maximum number of bytes required to store the file. The “see step” references are to the steps following the formula that explain the individual components of the formula.
File size in bytes =
(page size *
   (number of data pages [see step 1] +
    number of index pages
[see step 2] +
    number of variable pages
[see step 3] +
    number of other pages
[see step 4] +
    number of shadow pool pages [see step 5] ))
+ (special page size [see step 6] *
  (number of PAT pages
[see step 7] +
   number of FCR pages + number of reserved pages
[see step 8] ))
Determining file size requires that you account for two different categories of pages. The standard page category includes the pages when a data file is first created (see also Create (14) in Btrieve API Guide). In addition, the formula must account for special (non-standard) pages as listed in Table 25. The special pages are not always a multiple of the file page size.
1
Number of data pages =
#r /
( (PS - DPO) / PRL )
where:
2
For each index that does not allow duplicates or that allows repeating-duplicatable keys:
Number of index pages =
( #r /
( (PS - IPO) / (KL + 8) ) ) * 2
where:
For each index that allows linked-duplicatable keys:
Number of index pages =
( #UKV /
( (PS - IPO) / (KL + 12) ) ) * 2
where:
The B-tree index structure guarantees at least 50 percent usage of the index pages. Therefore, the index page calculations multiply the minimum number of index pages required by 2 to account for the maximum size.
3
Number of variable pages =
(AVL * #r) / (1 - (FST + (VPO/PS))
where:
*Note: You can gain only a very rough estimate of the number of variable pages due to the difficulty in estimating the average number of records whose variable-length portion fit on the same page.
4
The sum of steps 1, 2, 3, and 4 represents the estimated total number of logical pages that the file will contain.
5
Size of the shadow page pool = (number of keys + 1) * (average number of inserts, updates, and deletes) * (number of concurrent transactions)
This formula applies if tasks execute Insert, Update, and Delete operations outside transactions. If tasks are executing these operations inside transactions, multiply the average number of Insert, Update, and Delete operations expected in the inside transactions times the outside-transactional value determined by the formula. You must further increase the estimated size of the pool of unused pages if tasks are executing simultaneous concurrent transactions.
6
Determine special page size from Table 25 by referencing file version and data page size. Depending on the file format version, the pages sizes for FCR, reserved, and PAT pages are different from the normal pages sizes for data, index, and variable pages.
 
7
Every file has a minimum of two PAT pages. To calculate the number of PAT pages in a file, use one of the following formulas:
For pre-8.x file formats:
Number of PAT pages =
(((sum of pages from steps 1 through 3) * 4) /
(page size - 8 bytes for overhead)
) * 2
For 8.x or later file formats:
Number of PAT pages =
2 * (sum of pages from steps
1 through 3 /
number of PAT entries)
For number of PAT entries, see Table 25 and look up file version and data page size.
8
Include 2 pages for the file control record (FCR) pages (see also File Control Record (FCR)). If you are using 8.x or later file format, also include 2 pages for the reserved pages.