Variable scope, libraries

Aeturnalus:
The documentation you're looking for isn't available from Arduino because they didn't write the compiler, and few people need to know the underlying details. You can look here for the avr-libc documentation, which covers all the stuff you're wondering about.

I suggest to add such a link in the library tutorial/documentation. I don't understand how one can use safely a language without knowing its specifications.

This is too much for me, an array of pointers is fine. The funny thing of the story is that I don't like object programming, but anyway.

This is exactly what I want. The solution I currently use is creating an "dummy" instance with a default constructor. I override operator =, and do something like this:

listofa[index] = A(x,y);

This is pretty ugly, but it works.

jraskell:
Let me just repeat one last time: On platforms with such limited memory footprints, dynamic allocation is rarely of any true benefit.

Rarely is not never

jraskell:
If you don't have enough memory to handle your worst case scenario, dynamic allocation isn't going to help that, because it actually adds overhead, since you not only need memory allocated for the object itself, but you need at least one pointer for each object allocated as well.

If you do have enough memory to handle your worst case scenario, then just code for that scenario. Your code will be cleaner, simpler, easier to read, and probably most important of all, easier to debug as well. I'll tell you ahead of time, memory leaks and memory fragmentation can quickly cripple an Arduino.

I start over the explanation. My object of type B stores a table of objects of type A. Each object of type A contains an unsigned int and several tables of objects (2 bytes + 2 unsigned int = 6 bytes). I do not know the size of these tables, except they are the same for a given instance. If n is the number of objects of type A, and tn the size of the lists of object n:

  • size of object n = 2 + 6 * tn (+4 pointers?)
  • size of all objects = sum(1,n) (2 + 6 * tn (+4 pointers?)) (+1 pointer?)
    I clearly have a trade-off between the maximum n, and the maximum tn. In some cases I can have few big objects (small n, large tn). In other cases I can have a lot of small objects (large n, small tn). If I use a fixed value for both n and tn, I cannot manage both cases. So I prefer to use (4 * n + 1) pointers and have this liberty. I will most likely never have a lot of big objects. And in that case, I will just not create them.