for each letter in the alphabet i have an int-array declared like this:
int const A[64] ={
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,1,1,1,0,0,0,0,
0,1,0,1,0,0,0,0,
0,1,1,1,0,0,0,0,
0,1,0,1,0,0,0,0,
0,1,0,1,0,0,0,0,
0,0,0,0,0,0,0,0
};
then i create another array with pointers to these.
int const * text[] = { A, B, C };
this works fine, until that text array reaches a certain number of different entries.
for example this works:
int const * text[] = { A, A, A, A, A, A, A, A }; // could even go on much longer
but this crashes:
int const * text[] = { A, B, C, D }; // it seems the number of different entries matters
why is that? i thought that if it is pointers, then it should not matter what it points to it will always be of constant size?
note that this is run on the arduino platform, which has very limited memory.
I suspect that lookup into an array with identical elements is being optimized; If int const *text[];
were declared in a header file and compiled (defined) in a separate object file, you would likely see the same problem. The linker is doing the best it can, but all that data is likely overlapping with the heap / stack space.
At least with avr-libc (using avr-gcc, avr-binutils), there are macros, or variable attributes, that can place this sort of constant data in the much larger, read-only program space (flash ROM).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With