Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4824

SDK • Saving/restoring C++ instances to/from flash

$
0
0
My program collects data from the ADC and stores it to RAM until it is uploaded via the UART. There is a C++ class that collects the data and another that keeps statistics about the event and contains the collector. The classes know how to format and upload their data, so it makes sense to use those classes to do so with data stored in flash. Obvious problem is not enough RAM.

Is there a known way to write the objects to flash, then restore them later? Is it as easy as storing the objects, starting from the instance pointer for sizeof(<class_name>) bytes? I could maintain an address map in RAM to hold the flash offsets/addresses where the objects are for later retrieval. That would require that the data be uploaded before powering down, which is fine.

Since the objects hold pointers to other objects, the objects would need to be restored to the same memory location as they occupied originally, else there would need to be relocation information to correct the address offsets. I don't think I need to copy the instance data to another location to pad the block up to the next full flash page, since there is no memory protection to prevent the flash routines from reading past the end of the instance's allocated memory space.

Thanks,
Scott

Statistics: Posted by OAvKart — Fri Mar 01, 2024 2:59 pm



Viewing all articles
Browse latest Browse all 4824

Trending Articles