mco_flashsim_memory_size

Calculate the amount of memory required to store the internal state of a flash memory simulator.

Prototype

    mco_size_t mco_flashsim_memory_size(
        /*IN*/ mco_flashsim_params_t *params
    );

Arguments

params
Pointer to a mco_flashsim_params_t structure containing the desired flash geometry and configuration (page size, number of blocks, etc.).

Description

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:

The returned size depends on whether the simulator is configured for memory-based or file-based operation:

This function must be called before allocating the memory device used in mco_flashsim_open().

Return Value

mco_size_t
Number of bytes required to store the simulator’s internal state for the given configuration.

Example

    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(&params);
    dev.type = MCO_MEMORY_CONV;
    dev.dev.conv.ptr = (char*)malloc(dev.size);
    dev.dev.conv.flags = 0;

    // Now open the simulator...

Files

Header file:
mcoflashsim.h
Source file:
mcoflashsim.c
Library:
libmcoflashsim.a