In Memory vs Flash for Due Performance

Hello,

I have to store 12000 numbers generated using the equation y = 1 - (2/(4*x+1)) where y is the resulting value and x is the index 0 - 11999, the result are used to increase or decrease another number which is irrelevant, instead of evaluating the equation I have decided to loop through all 12k possible values and keep them in an array and reuse the result.

so what've done is this:

#define nMax 12000
#define calcNFactor(n) (1 - (2.0f / ((4 * n) + 1)))
float nValues[nMax ]{};
void setup() {
	for (int n = 0; n < nMax ; n++)
	{
		nValues[n] = calcNFactor(n);
	}
}

Then pass a pointer to the array to multiple classes so it uses the same array.
Can this be done any better?
Would it be faster if I used flash memory?

Thanks.

Flash sounds great but it is not always the easiest to use and has limited write cycles. Have you considered FRAM, you can read and write as fast as you can manipulate the IO with no write delays involved. Those modules come with a lot of memory and they are non volatile so if you lose power you do not lose your data.

SRAM is normally much faster than EEProm to read.

Your array will take up 1/2 of the total SRAM on the Due - which may limit the rest of your code.

If you need to use EEProm then try an experiment of reading a float from EEProm to see how long it takes compared with calculating it - you may find the calculation is faster.

You don't tell what speed constraint you may have in your code.

@countrypaul,

To my knowledge a Due does not have EEPROM :wink:

sterretje:
@countrypaul,

To my knowledge a Due does not have EEPROM :wink:

Perhaps I've badly structured my posting as I did not mean to imply the Due has EEPROM, but I can see how anyone not familiar with a Due could read that in my comment, thanks for highlighting that.

Unlike a DUE board, a DUE Core (100% compatible arduino DUE) has an I2C EEPROM :slight_smile: :

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.