Calculate the amount of memory required to store the internal state of a flash memory simulator.
mco_size_t mco_flashsim_memory_size(
/*IN*/ mco_flashsim_params_t *params
);
params
mco_flashsim_params_t structure containing the desired flash geometry and configuration (page size, number of blocks, etc.).This function computes the total memory footprint (in bytes) needed to initialize a flash simulator instance with the specified parameters. The result includes space for:
- Simulator metadata (e.g., timing, error injection settings),
- Page state tracking (programmed/erased status per page),
- Block state tracking (erase count, bad/error flags per block),
- Actual flash data storage (if operating in memory-based mode).
The returned size depends on whether the simulator is configured for memory-based or file-based operation:
- In memory-based mode (
file_based = MCO_NO), the size includes the full flash image in RAM.- In file-based mode (
file_based = MCO_YES), only metadata and buffers are allocated in memory; flash content resides in a file, so the required memory is significantly smaller.This function must be called before allocating the memory device used in
mco_flashsim_open().
mco_size_t
mco_flashsim_params_t params = {0};
mco_device_t dev;
// Configure flash geometry
params.page_size = 4096;
params.pages_per_block = 64;
params.n_blocks = 1024;
params.file_based = MCO_NO; // memory-based
// сreate a memory segment for the flash simulator
dev.assignment = MCO_MEMORY_ASSIGN_PERSISTENT;
dev.size = mco_flashsim_memory_size(¶ms);
dev.type = MCO_MEMORY_CONV;
dev.dev.conv.ptr = (char*)malloc(dev.size);
dev.dev.conv.flags = 0;
// Now open the simulator...