I have a question or two about memory management. For the past couple of months I have been learning C/C++ from what I could glean from the internet and the Arduino help and example code. I have a Arduino Mega and an Ethernet shield. I started writing a web server as practice at learning C. Everything was going well, the server has become a fairly full featured server and runs well, serves up files, controls IO Pins and returns data from attached sensors. Suddenly I began getting system lockups. The first was when I began parsing the GET request from the Network Configuration page. Anyway, long story short, I believe what I am experiencing are stack/heap collisions. After visiting the Atmel site and looking through the AVR Libc Reference Manual I am almost positive. So, another rewrite is coming. But before that I wanted to know how certain things are stored, and in what part of memory.
For example:
client.println("<html>\r\n<head><title>Something Meaningful</title></head>");
Is the text stored in program memory as a string literal or stored in SRAM?
Also, is it better to declare global variables rather than have functions create and free up the memory to avoid fragmentation?
And finely, is there a way to use an array of chars rather than a String object with functions such as FileType.name(); from the SD library? Or should I just initialize a String as a global variable with a reserved size?
It was the String in the parsing function that was crashing the program. So any info would be helpful, and thanks in advance for any replies.