memory usage and arrays


i curious, if declared 4 arrays, of type int, compiler allocate memory needed populate each array?
or need worry using memory?
an example be:
program uses 70% of total available memory @ initiation.  included in deadspace 0 value of arrays?  or space needed populate 0 array @ startup?
memory % part guessing  - net result, array padded @ initiation or grow in memory values stored?
narf - hope makes sense  :)
thanks!!

the short answer compiler allocate memory.

memory static variables including arrays no or partially initialized data allocated when system start up. variables declared outside of function static.

variables declared within function have memory allocated memory stack @ runtime unless variable explicitly declared static. if insufficient memory available these stack variables, system crashes.

it possible dynamically allocate memory using functions malloc tricky because of difficulty of handling case need memory there none left get. imho using malloc asking trouble.

so, if memory tight, advice is:
- think moving constant data,  particularly strings, progmem
- use smallest appropriate data type
- closely @ big arrays see if can find more efficient ways of managing data.


Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > memory usage and arrays


arduino

Comments

Popular posts from this blog

CAN'T INSTALL MAMBELFISH 1.5 FROM DIRECTORY - Joomla! Forum - community, help and support

error: expected initializer before 'void'

CPU load monitoring using GPIO and leds - Raspberry Pi Forums