Yes, you should be concerned with the endurance of the flash. The spec says it’s guaranteed for a minimum of 10,000 cycles, 100,000 cycles typically. The RAM has some load levelling capabilities so you would see better than that, but it’s not the right way.
As to your serialisation example, when you store the serialised object, first store the length of the serialised object (as an int) then the serialised object itself.
Then when you get the object back out, you start by reading the length as an int, then instantiate and read in the serialised object itself to that length.
public static void WritePersistentCounters()
byte buf = Reflection.Serialize(Counters, typeof(PersistentCounters));
// Save length as bytes
public static void InitializePersistentCounters()
// Read length as int (4 bytes long - from sizeof(int))
byte buf = new byte[read_in_serialised_length];
BatteryRAM.Read(0, buf, 0, read_in_serialised_length);
Counters = (PersistentCounters)Reflection.Deserialize(buf, typeof(PersistentCounters));