Memory Mapped Files in Delphi

TMapStream provides high level access to Windows memory mapped files. Memory mapped files provide a fast and convenient way of sharing large amounts of data between applications running concurrently. It has one property

The principal methods of TMapStream are listed below

Usage: Sharing data between applications is a four step process
  1. Each application - they can be different applications or instances of the same application - creates a memory mapped file identified by the same name. It is advisable to use long names containing numbers and underscore characters so as to ensure that you do not accidently grab a handle to another mapping created by a wholly unrelated application. If the map already exists, we simply get a handle to it. Otherwise, Windows creates a new mapping.
  2. The application(s) use TMapStream methods to manipulate the memory map. In complex applications the return value from the methods should be checked since they may fail owing to mapping being in use by another application.
  3. When an application writes to the map it is usually with the intention of sharing data with other applications. Evidently, it is necessary to inform the other applications that data are available for reading. Windows messages are used for this purpose.
  4. The application must also listen in for messages telling it that data written to the map by other applications are available for reading.
The techniques required to accomplish all of the above are demonstrated in the test application, MapTest. The source code for TMapStream is available for just $9.99.
Download
Jump To...

Colophon