I was looking into optimising the memory use of some code that runs on 001 & 002 HW (hence quite RAM limited ) and wanted to check some coding good practices used the eImp libraries. In the SpiFlash lib, I found this code snippet which kind of made me wonder how internally temporary memory iallocation is done :
` // spiflash.read(integer, integer) - Copies data from the SPI flash and returns it as a series of bytes.
function read(addr, bytes) {
// Throw error if disabled
if (!_enabled) throw SPI_NOT_ENABLED;
_cs_l_w(0);
_spi_w(format(SPIFLASH_READ, (addr >> 16) & 0xFF, (addr >> 8) & 0xFF, addr & 0xFF));
local readBlob = _spi.readblob(bytes);
_cs_l_w(1);
return readBlob;
}
// spiflash.readintoblob(integer, blob, integer) - Copies data from the SPI flash storage into a pre-existing blob.
function readintoblob(addr, data, bytes) {
data.writeblob(read(addr, bytes));
}
`
Question : the way readintoblob() is implemented is different then I would expect. I would have expected an almost complete copy of the read() code, but with “data.writeblob(_spi.readblob(bytes))” instead of local readBlob = _spi.readblob(bytes); Would that be a more optimal use of RAM - because there’s one less temp blob needed, or doesn’t that make a difference (because for instance the writeblob() function allocates the same temporary memory under the hood ? Especially when large chunks of data are read from the EEPROM, allocating one more temp blob for eg 5K bytes can make a serious difference