My app creates nodes dynamically based on provided configuration file and I was struggling for some time with strange node/property names. Then I realized that while node/property id is copied using strdup, node/property name, unit, datatype, format are only referenced
Example of problematic code:
for(int j=0;j<NUMBER_OF_VALVES;j++){
String vid = valves[j]->getIdStr() + String("rt");
String vin = valves[i]->getIdStr() + String(" Runtime");
prg_node[i]->advertise(vid.c_str()).setName(vin.c_str()).setDatatype("integer").setFormat("0:120").settable();
}
In above code:
- setting property id works without problem
- setting property name is an issue as string buffer is released after finishing the cycle
I assume the reason is saving memory by avoiding string duplication.
Question
Would it be OK to copy all strings to achieve more consistent behavior? And for memory limiting situations implement e.g. setName with progmem signature, so developer can store strings to progmem and setName will copy them from there?
I can create PR for that.
My app creates nodes dynamically based on provided configuration file and I was struggling for some time with strange node/property names. Then I realized that while node/property id is copied using
strdup, node/property name, unit, datatype, format are only referencedExample of problematic code:
In above code:
I assume the reason is saving memory by avoiding string duplication.
Question
Would it be OK to copy all strings to achieve more consistent behavior? And for memory limiting situations implement e.g. setName with progmem signature, so developer can store strings to progmem and setName will copy them from there?
I can create PR for that.