How to create and free dynamic arrays with Arduino

The other thing to bear in mind with malloc() is that it is not re-entrant (at least on AVR) so no one should write an task [ISR] which can asynchronously grab memory while it is being released in the main loop(), which would otherwise mess up any attempts by the programmer to minimise fragmentation of the heap by structuring the use of malloc() and free() to cleanly unwind any storage allocations. I discovered this or, better put, it was pointed out to me by @drmpf during an sustained attempt to "break" the String class which, incidentally, I found surprising difficult when following all the rules. Convert string array to byte array - #8 by 6v6gt