It's my experience that you should never use dynamic memory allocation (operator new, malloc, or things that use them) on microcontrollers. There's just too much that can go wrong with fragmentation, heap running into stack, interrupts, etc.
Fixed buffers are the way to go. If you need to call "new" to create something, use placement new:
#include <new>
char storage[sizeof(MyThing)];
MyThing *ptr = new(storage) MyThing(arguments);
Also, some other things mentioned in this thread:
- An array of charais actually a byte-sized (or rather, byte-aligned) piece of data. This will have sizeof() 6:
struct stuff {
char a[3];
char b[3];
};
- A fixed-size array does not use heap. It uses global data segment space (if global/static) or stack space (if local.) There is no risk of fragmenting either.