# NAND Flash Simulator

> The Flash Simulator allows developers to build applications for unmanaged flash devices without needing physical hardware. Instead, data is stored in memory or in a file. By default, the simulator allocates all emulated flash memory in memory, essentially acting as a RAM disk. In this mode, flash contents can be saved to a file when closing the simulated device and reloaded on the next run.

> However, this approach has some drawbacks. If the application crashes, saving the image may not always be possible, and memory constraints could become an issue. To work around this, the simulator supports flash emulation both in memory and in a file. In this case, only a small header containing control structures is stored in memory, while the flash content resides exclusively in the file.

> Additionally, the simulator enables performance evaluation of database operations based on user-defined delays for basic flash operations (read, program, erase, and copy).

> The simulator is configured using the `mco_flashsim_params_t` structure, defined in `include/mcoflashsim.h`.

> ## Usage:

> To use the simulator, an application must be linked with the `libmcoflashsim.a` library:

>         gcc -o my_app my_app.c -lmcoflashsim

> ## Support for eXtremeDB/rt Storage Options:

> The Flash Simulator provides comprehensive support for both storage approaches in eXtremeDB/rt:

> - Transactional File Mapping (xFile module): When using the xFile module, the flash simulator can emulate a block device (e.g., an SD card). This allows developers to test and validate their database applications without physical flash hardware. The emulated block device can be used either with an external file system or with eXtremeDB’s built-in `mcofblkdev` layer, which implements the `mco_file_h` interface directly over block storage.
> - Transactional Flash Translation Layer (xFlash module): For applications requiring direct raw flash access, the simulator emulates the low-level NAND/NOR flash characteristics needed by the xFlash module. This enables developers to test the deterministic, real-time performance of their database operations under the control of eXtremeDB/rt's transactional FTL.

> This dual support makes the Flash Simulator an invaluable tool for developing and testing eXtremeDB/rt applications across different storage configurations, from rapid development with file-based storage to mission-critical real-time systems requiring raw flash performance.

> ### See also:

> - Source Code Configuration (mco_flashsim_params_t)
> - Simulator Configuration File
> - Using the Simulator (example)