Indexed Binary Record Store
A fixed-size-record binary file naturally supports random access by offset (slot N sits at N * recordSize), but that only works cleanly until the first delete - either the file has to be compacted (rewriting everything after the gap) or "slot number" and "record id" quietly stop meaning the same thing. This library keeps them deliberately separate from the start. Every record is stored at some physical slot, but callers always address records by their own integer id, resolved through an in-memory sorted id-to-slot index built by scanning the file's own per-slot flag bytes at Open() - no separate index file that could go stale relative to the data file. Get/Update/Delete are a binary search plus one seek, not a scan. Deleting a record tombstones its slot and pushes it onto a free-list; the next Insert() reuses the lowest-numbered free slot before ever growing the file, so a store that has many deletes and re-inserts over its lifetime does not grow without bound. Reopening a store from disk rebuilds the index and free-list purely from what is actually written - so the demo closes and reopens the file mid-run and shows the index comes back correctly, including the effect of the delete and slot-reuse that happened before the close. Notes and limitations - Records are fixed-size raw byte payloads - the caller packs and unpacks whatever structure it needs (the demo packs a short text string; a real EA would more likely pack fixed-width numeric fields). There is no schema or type checking on the payload content. - Ids are plain 32-bit ints, not longs - the header field is 4 bytes wide. Broker order tickets that exceed INT_MAX on some brokers would need the id field widened before use as a direct ticket key. - Delete() does not shrink the file - freed slots are reused, but the file never gets physically smaller. A store with a very large delete churn relative to its live record count will carry that dead space as file size, just not as index/lookup cost. - Not safe for two terminals/EAs writing to the same file concurrently - there is no locking here.
Script · MT5 · v1.0 · Free
About Indexed Binary Record Store
Indexed Binary Record Store is a script for MetaTrader 5. MQL source code included.
Files in the download: IndexedBinaryRecordStore.mq5.mqh, IndexedBinaryRecordStore.txt, IndexedBinaryRecordStoreDemo.ex5, IndexedBinaryRecordStoreDemo.mq5.
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Scripts.
- Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
- Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the script onto a chart to run it once.
Tags: Binary Options · MT5 Script · MQL5 Source Code