SRAM Issues

So, I have a fairly complicated project that is utilizing the new Ethernet shield with the sdfat library (For the built in SD card functionaity) as well as the standard ethernet library, TIE, and UDPBytewise among others. My list of incudes is as follows (using version 0020):

#include <SdFat.h>
#include <SdFatUtil.h>
#include <Client.h>
#include <Ethernet.h>
#include <Server.h>
#include <SPI.h>
#include <WebServer.h>
#include <Time.h>
#include <UdpBytewise.h>

Everything works fine, but when I make FreeRam() calls, I notice that my RAM is down around 400 bytes. As soon as I open up a SD card file, by RAM drops dangerously low to around 150 bytes and sometimes hangs or reboots automatically (Weird behavior). As I have been trying to add functionality to my application, it often runs out of RAM, and then I have to spend up to several hours trying to optimize to squeak every last drop out of the built in RAM. For larger applications it would seem that the 2k just doesn’t cut it. As I am trying to build a low cost device, the Arduino MEGA is a steep double the cost of the UNO, so I am trying to make it work without upgrading. Not to mention the form factor is a little large on the mega for my purposes. If I must, then I probably will, but I’m hoping to find something in between the two.

Does anyone have any thoughts about how I may be able to get a little more RAM? Even 3k or 4k would definitely do the trick, but my application requires some buffers for reading in HTML from the SD card, and doing comparisons which are eating up the RAM, and there really seems to be no way to shorten them any more than I have. The libraries seem to be devouring most of it, since if I do a FreeRam() call immediately after boot, I have only about 400 bytes left. This is while the unit is idle in webserver mode waiting for connections.

Any thoughts would be appreciated!

As an update, I spent the last little bit researching the fat16 library to look to conserve some memory. I have met with some good success, and discovered a couple of things along the way that may be useful to others.

I adapted the fat16 library to my application, but received the standard init failure:

card.init failed SD error errorCode: 1 errorData: FF

To make the chip work with the new SD compatible ethernet shield, I had to set pin 10 on my arduino to output high to enable SPI communication. Then, I had to initialize the SD card with F_CPU/2 and pin 4 as the SS pin as follows (Thank you LadyAda! http://www.ladyada.net/learn/arduino/ethfiles.html):

SdCard card;

pinMode(10, OUTPUT); // set the SS pin as an output digitalWrite(10, HIGH); // but turn off the W5100 chip!

// initialize the SD card if (!card.init(0,4)) error("card.init");

// initialize a FAT16 volume if (!Fat16::init(&card)) error("Fat16::init");

Now I have around 700 bytes of RAM left at runtime, and when I read files from the card, it only dips to around 600 bytes free with no odd behavior. Any other tips would be appreciated, but I think I'm finally moving forward again! :)