I know that Arduino's String.replace function uses realloc().
Is my "replacement" function, which builds a char buffer and then assigns it to the input String, any better in terms of dynamic memory allocation?
I know I should not be using String in the first place, but I am stuck with it for the time being.
This is my function:
void replaceSubstr(String& in, String subin, String subout){
int s = in.indexOf(subin);
if(s > -1)
{
int a = in.length();
int b = subout.length();
int c = subin.length();
int len = (a + (b - c))+1;
char buff[len];
memcpy(buff, in.c_str(), s);
memcpy(&buff[s], subout.c_str(), b);
memcpy(&buff[s+b], in.substring(s+c).c_str(), a-(s+c));
buff[len-1] = '\0';
in = buff;
}
}