EEPROM put() with a struct

I am using EEPROM to save a large number of user settings and a few runtime stats. Currently all the variables are stored in a struct and loaded into the EEPROM using .put().

The reference documentation mentions the .put() function compares the new data with the currently saved data to reduce the number of bytes written to flash, but I’m wondering if it does this for the whole object or on an individual byte level.

For example… If one value in the struct changes, does the EEPROM only write the changed bytes or will it rewrite the entire struct?

Most of my saved values will never change after the first configuration, but some of the runtime stats are saved regularly. By storing them all in the same struct and saving it to EEPROM frequently, am I putting excessive wear on the flash pages?

Would it make more sense to store the settings and runtime stats in different structs?

Good question!

One could assume that the check is on a byte by byte basis, but it is not 100% clear.

Solution is to have a look at the DeviceOS code (and report back!)

On Gen 2 (Photon, P1, Electron, E Series) it’s per byte.

On Gen 3 (Argon, Boron, B Series SoM, Tracker SoM), EEPROM emulation is a file on the LittleFS file system, so, with a few exceptions, writing any byte within a 512 byte sector will copy the whole sector. However, there are a large number of sectors (8192 on the Tracker SoM, 4096 on other Gen 3) vs. 2 sectors on Gen 2, so wear isn’t as much of an issue on Gen 3.

1 Like

@Dueck456 don’t forget to mark your post as solved!

Thanks for the reply,

I am using an Electron (soon to be E-Series) for this project.

I just want to make sure I understand your response clearly.
If I change one value in a struct and resave it to EEPROM, only the changed value is copied to EEPROM, not the entire struct. Correct?

If I change one value in a struct and resave it to EEPROM, only the changed value is copied to
EEPROM, not the entire struct. Correct?

Only the changes, not the entire struct, are written to flash.