My intention is to read a file (of max. 128 KB) from an SD card and store it in (external SRAM). I will use an Arduino Mega which has 8 KB of internal SRAM but even 8 KB is not really much for some processing and keeping some administrative instances of classes always available. I don't need SD access after the copy process anymore.
Would it be a crazy idea to change the SD library buffer instead of using a global or internal buffer in the SD library, instead to pass a local variable which is removed automatically after the copy function ends?
So in other words, I create the SD buffer as local variable, I call the SD library using instead the buffer I created, and afterwards the local variable (buffer) will be removed, saving me 512 bytes.
Of course I will only do this when getting into SRAM problems, but I think there is a chance to get into this.
The reason I want this. In my project (at least initially), I want to process (fast) MIDI messages, that means receiving MIDI messages, process them and send MIDI messages. Since this needs to be done in about 10-20 ms (between receiving/sending), performance is important.
The configuration of the processing can be completely configured (via an external program). The configuration file will be written to a (micro) SD card. The typical size of such a file will be between 1 and 128 KB. Since it will be to slow for every incoming MIDI message to read the SD card, the content of the SD card (max 128 KB) will be copied to SRAM.
So after this 'copy' I do not need the SD card (reader) anymore, so the 512 byte buffer is never used anymore.
(maybe in the future I will make some way to alter the configuration on the Arduino, with an LCD/keypad, but even than the saving of a configuration file will be a very occasional task where I can make the 512 byte buffer temporarily).
During processing I might need more (internal) SRAM. SInce I expect my application will contain quite a bit of classes/functions so the stack can grow; also I need to store intermediate result. Of course I also can store this in the external SRAM, but it will be much less comfortable.