I'm writing a program for arduino that needs dynamic memory allocation frequently, but as I don't want the memory to get fragmented, I'm also writing a "memory handler" for it. This memory handler would need to do calculations involving both pointers and
size_t variables, like this (example code is not part of program, but the structure of the calculations is the same):
size_t freeMemSize = nextPointer - currentPointer - currentSize;
Which would calculate the size of free memory between two reserved spaces.
Of course, arduino doesn't want to swallow this code, as it compares incompatible types. My questions are:
- Is a cast to the correct integer type enough to solve the problem?
- If it is, what is the "normal integer" counterpart of a pointer?
I guess this varies from processor to processor, so I should look for something like size_t, but for memory indices instead of sizes.
Board: Uno, Nano
IDE version: 1.8.2