KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: How does 4D optimize Selection storage?
PRODUCT: 4D | VERSION: 13.1 | PLATFORM: Mac & Win
Published On: September 20, 2012

A selection can be stored internally in at least 4 different ways. 4D automatically chooses the most optimized form.

  1. If there are less than 1,024 records in the Selection, the Selection is simply an array with one element per record.
  2. If the Selection is unsorted (ORDER BY never used), 4D uses a set. See this Tech Tip for information about how 4D optimizes Set storage.
  3. Larger Selections use a kind of master array, which refers to secondary arrays that each handle 1024 records. Note:
    • This data structure is not one big block in memory. Much like a Set it is a tree-based structure split into many smaller objects. This allows it to be more flexible and avoid memory fragmentation.
  4. If there is not enough cache space available and it is not possible to purge objects to create space, Selections can be stored on disk using the temporary folder. Reminder: the temporary folder is defined in the database Settings. These Selection files will have names like "123456.tmp".

Perhaps the most important thing to understand is that Selections may be stored as Sets, which are very memory efficient. And regardless of the storage mechanism (array, Set, Selection) the design is flexible enough, so the size will be very different to calculate and that they do not require one big memory block.

See Also: