Using RAII for wrapping the littlefs C library
RAII is a simple yet powerful C++ technique used to manage resources through an object’s lifetime. Resources can represent different things. Resources are acquired when an object’s lifetime begins, and they are released when the object’s lifetime ends.
The technique is used to manage resources such as dynamically allocated memory. To ensure that the memory is released and avoid memory leaks, the recommendation is to use dynamic allocation only internally in classes. When an object is instantiated, the constructor will allocate memory, and when the object goes out of scope, the destructor will release the allocated memory.
The RAII technique can be applied to other resources beyond the dynamically allocated memory, such as files, and we will apply it to the littlefs
filesystem library (https://github.com/littlefs-project/littlefs). We will start with a short overview of littlefs
– a filesystem designed...