Declaring and initialize tab

Hi

Is it possible to declare an array like that :

int _tabDistSamples[1000];

and init it like this :

      _nbDistSamples=1000;
    for (int i = 0; i < _nbDistSamples; ++i)
    {
        _tabDistSamples[i]=0;
    }

If you declare the array with global scope, you get a one-time initialisation to zero for free.
memset may be a quicker option if you need to reinitialise.

However, remember a 1000 element int array may be pushing the limits of available RAM.

No it is declared into class.

I need to replace int by uint8_t to get it works.
Otherwise I have a bad program.

Maybe it is just the size of array that make problem.

Passing length from 8 to 400 cause serious bad init.

The arduino "core" will use almost 500Bytes of ram, add 1000 bytes of ram in one uint8_t array and 2 or 3 functions and some other variables and you are out of ram.
Think of another way to solve your problem or add extra ram using maybe spi/i2c RAM from microchip.

I know that I can calculate memory used by adding all data types.

Is there a free tool that do profiling in this way ?

(my sketch is restarting so I think I am out of memory)

No profileing tool I'm aware of but this thread might be interesting - http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1213583720;start=all

Can you post your complete code?

This function

      // this function will return the number of bytes currently free in RAM
      // written by David A. Mellis
      // based on code by Rob Faludi http://www.faludi.com
      int availableMemory() {
            int size = 2048; // Use 2048 with ATmega328  or 1024 with ATmega168
            byte *buf;

            while ((buf = (byte *) malloc(--size)) == NULL)
                  ;

            free(buf);

            return size;
      }

Returns to me 203. I think it is 203 bytes free.

Is it ok to continue to add some variables?

Is it ok to continue to add some variables?

Depends on when and where you are calling that function. Each function call takes up stack space, which will reduce that value.

I call it in the loop.

203 bytes is very small free ram no ?

203 bytes is very small free ram no ?

Out of 2000?, No, not really.

It is 203 kbytes no ?

Now I am at

179

many times displayed in the main loop.

Is it 179 bytes or kbytes ?

Bytes.
You've got the source.
Read it.

Yes so 179 bytes is not so far from out of memory

As long as there is one byte left, you are not out of memory. Don't forget, though, that function calls take up space, so the calls to the free memory function in loop do not tell the whole story.