What is the limit for array size on Arduino DUE?

Hi, I am trying to create 4KB array to store data, but I am not very lucky with that. When writing

byte arr[4096] = {0};

I get error:

ArduinoSecurityAccess:21: error: too many initializers for 'byte [0]'

While when skipping the explicit initialization, the program compiles, however, it is not running correctly. The array is declared outside the setup() or loop(). By trial and error, I found out that array size 1023 bytes is okay, but I start getting errors using array of size 1024 bytes.

I had an impression that Arduino Due has 96KB of memory and an array of this size should not be a problem. Am I doing something wrong? How can I get that large array to work?

Thanks

You could do the initialisation in "setup" with a memset or a memclr.

I had an impression that Arduino Due has 96KB of memory and an array of this size should not be a problem.

Seems right to me.

Am I doing something wrong?

Well, you didn't post all of your code.

How can I get that large array to work?

You need to define what doesn't work.

Global arrays are initialized to 0 by default. So, supplying an initializer to initialize one element of the array to the default value doesn't seem useful.

It might be, and I'm just guessing here, that the compiler doesn't properly initialize arrays that large. You could put a for loop in setup() to initialize it.

Thanks for all your answers, but I found the problem already, and it is far more simple. Luckily, the compiler does a good job. unluckily, I am idiot, because I actually did not posted the exact code I was using, which was:

byte size = 4096;
byte array;

I missed that size overflowed, therefore initializing empty array - that is why it crashed while trying to initialize it explicitly. And that is the reason while with size = 1023 it worked, since it interpreted it as 255.

I feel ashamed.

I feel ashamed.

The man with insight enough to admit his limitations comes nearest to perfection.
Johann Wolfgang von Goethe
Read more at Admit Quotes - BrainyQuote

I think the cleanest way to declare an array is using a #define directive:

#define ARRAY_SIZE 65536   // maximum for Due
uint8_t array[ ARRAY_SIZE ];

I think the cleanest way to declare an array's size is using a "const unsigned long"

Well, my arguments in favor of #define are:
1- It is a constant that can not be modified later in the program
2- It does not waste ram memory
A constant variable meets the first point
I am not sure if it meets the second one?
Is there another argument in favor of a constant variable?

The compiler optimizes const variables so they do not use RAM either.

a #define can be used for conditional code further in the program. That is something a const cannot do.

e.g if the ARRAYSIZE is not defined all the code to store sensor samples in an array and do processing on it is removed.
Only the live processing part of the code will be available.

Thank you robtillaart for that clarification

gallegojm:
I think the cleanest way to declare an array is using a #define directive:

#define ARRAY_SIZE 65536   // maximum for Due

uint8_t array[ ARRAY_SIZE ];

IIRC I have used even bigger arrays. Like 93000 or something.