AI Glossary / AI and machine learning / Advanced
Memory map
Definition
A memory map is a file-access technique where a file on disk is mapped directly into a program's address space, so the program reads and writes it like ordinary memory while the operating system handles loading and caching.
What it means
The idea removes a copy. Instead of reading a file into a buffer, the program points at the file's bytes as if they were already in memory, and the system pages pieces in and out as needed.
That matters for the datasets machine learning loves: files bigger than RAM. A memory-mapped array lets a laptop scan a hundred-gigabyte table while holding only the pages in active use.
Memory maps also enable sharing: several processes can map the same file and see the same bytes without copying, which is how many feature stores and vector indexes serve models efficiently.
The technique has sharp edges: writes can persist unpredictably, files must have stable layouts, and a map ties performance to the disk and the operating system's paging decisions.
For a business, memory maps usually arrive inside tools rather than as a choice: they are why a vector database or a numeric library can search billions of items on ordinary hardware.
The same mechanism serves read-only workloads best, which is why it appears so often in search and analytics tools.
How it works
Open the file in mapped mode through the library or operating system, which returns an object that behaves like an in-memory array.
Read and write through that object; the operating system loads touched pages into memory and evicts cold ones under pressure.
Keep the file's layout fixed while mapped, since offsets are addresses; a schema change means remapping, not editing.
Flush or sync explicitly when durability matters, because a write to a map is not a promise that bytes reached the disk.
Close and remap to share across processes: each process maps the same file and sees consistent bytes without copying.
Three practical examples
- A numeric library memory-mapping a forty-gigabyte feature matrix so a training script reads it on a machine with sixteen gigabytes of RAM.
- A vector search index memory-mapping its stored vectors, letting one server answer nearest-neighbor queries over billions of items.
- A log analytics tool mapping archived files so analysts grep years of history without loading any of it fully.
Think of it this way
Think of a library with a paging service: the catalog lets you read any book, but only the books you actually open are brought to your desk. The building holds far more than your desk ever could.
Worked example
scanning a year of transactions on a laptop
Suppose an analyst must scan twelve months of transactions, ninety gigabytes, on a laptop with sixteen gigabytes of memory. The figures are illustrative.
Loading the file fails outright, but memory-mapping it succeeds: the analyst's script walks the records while the operating system pages chunks in and out behind the scenes.
The scan takes minutes, bound by disk speed rather than memory, and the laptop stays responsive because untouched pages never load.
The decision consequence: a task that seemed to need a server needed only a different file-access mode, changing the cost of the whole audit.
Illustrative case study
A fictional data team treated a memory-mapped feature file as scratch space, editing its layout while models trained against it, and produced weeks of irreproducible results.
Offsets had shifted under running readers, so the same query returned different rows on different days, and the corruption looked like model instability.
The invented lesson: a memory map is a contract about layout. Freeze the file while it is mapped, or every reader is reading a moving target.
Common misconceptions and mistakes
- Memory mapping loads the whole file. It loads nothing up front; pages arrive on demand and leave under pressure.
- It is always faster. For small files or one sequential pass, ordinary reads can match or beat it; the win is large files and random access.
- Writes are instantly durable. They sit in the page cache until flushed; durability needs an explicit sync.
Business use
Prefer memory-mapped access for datasets larger than RAM instead of buying memory to fit them.
Treat mapped files as immutable during use: rebuild rather than edit when the layout must change.
Ask vendors whether their search or feature-serving tools use mapping, since it explains performance claims on modest hardware.
Remember durability: if a mapped write must survive a crash, the design needs explicit sync points.
People also ask
What is a memory map in one line?
A way to treat a disk file as if it were memory, with the operating system paging pieces in and out on demand.
Why does machine learning use it?
Datasets and indexes often exceed RAM, and mapping lets programs work on them while holding only active pages.
Is it the same as caching?
Related but not identical: the operating system's page cache is the mechanism, and the map is the programming interface over it.
What is the main risk?
Layout changes under active readers, and assuming writes are durable before they are flushed.
Check your understanding
Why does a memory map let ordinary hardware work on datasets larger than its RAM?
Answer: Because the file's bytes are paged in only when touched and evicted when cold, so the working set, not the file size, decides memory use, and the disk becomes an extension of memory.
Related terms
- Vector Database
- Data pipeline
- Index
- memory
- cache
- operating system
Learn next
Be Productive Using AI builds the practical data-handling judgment behind choices like these: https://aiforbusinessandlife.com/academy/be-productive-using-ai. [C1]
More in AI and machine learning
- Maximum inner-product search - Maximum inner-product search is the task of finding the stored vector with the largest dot product with a query vector.
- Means - ends analysis - Means - ends analysis is a problem-solving strategy that compares the current situation with a desired goal, identifies an important difference and chooses...
- Medoid - A medoid is an actual member of a group of observations chosen to minimize the total dissimilarity to the other members.
- Meta-learning - Meta-learning, often called learning to learn, is training a model on many tasks so it adapts to a new task from very few examples, rather than starting...
- Meta-optimization - Meta-optimization is the use of an optimization process to improve the configuration or behavior of another optimization process.
- Mini-batch - A mini-batch is the small slice of training data, commonly 32 to a few thousand examples, used for each weight update instead of the whole dataset or a...
Sources
[S23] NumPy documentation, Broadcasting; [S12] Aalto University, Dictionary of Machine Learning. Full URLs are in the source ledger. Verified 11 October 2026.
Previous: Memory-level parallelism Next: Mendelian randomization