How to specify the size of a class array ?

dc42:
It's true that using dynamic memory allocation is usually best avoided in embedded systems (see Dynamic Memory Allocation in Critical Embedded Systems | David Crocker's Verification Blog for why). However, allocating dynamic memory using malloc or new in the initialization phase (i.e. in stuff called from setup()) is OK if you never release it.

Thank you for that very interesting and informative article.

dc42:
The template solution is also OK. One issue with using templates in embedded systems is that the code gets replicated each time the template is instantiated, leading to code bloat; but in this case you will only even instantiate the class once, so that doesn't apply.

You mean if I instantiate two classes with the same template parameters I have two copies of the same "generated" code ? That's interesting. Going to google a bit about that...

But yes, the idea is to have just one instance of that class per sketch.

dc42:
Have you considered using a linked list instead of an array? That way you don't need to know in advance how many boards there will be. The disadvantage is that you need a little more RAM to store the links.

That's an interesting option. For the use case I'm thinking about I think a statically sized array is a better option though.