<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><br class=""></div>I’ve committed (and pushed) an experimental extension to allow C++ objects to be optionally moved to SPI RAM.<div class=""><br class=""></div><div class="">The code is in ovms.h, so should be easily accessible to everything. It is pretty simple:</div><div class=""><br class=""></div><div class=""><ol class="MailOutline"><li class="">We have a new class ‘ExternalRamAllocated’. That does nothing except override the new and new[] operators.<br class=""><br class=""></li><li class="">Those operators try to malloc from SPI RAM first. If that doesn’t succeed then they fall back to standard internal RAM.<br class=""><br class=""></li><li class="">The definition of a C++ class can then be changed to make it “: public ExternalRamAllocated”. Once that is done, any objects of that class allocated will try to be placed in external (SPI) RAM.<br class=""><br class=""></li><li class="">For other malloc uses, a general purpose 'void* ExternalRamMalloc(std::size_t sz)’ function is also provided.</li></ol></div><div class=""><br class=""></div><div class="">To test this, I’ve made a one line change to the OvmsCommand class:</div><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">-class OvmsCommand</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">+class OvmsCommand : public ExternalRamAllocated</span></font></div></div></blockquote><div class=""><br class=""></div><div class="">Here is what the memory usage looks like:</div><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">With SPI RAM disabled (in menuconfig):</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class=""><br class=""></span></font></div></blockquote><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">Free 8-bit 120844/284304, 32-bit 30508/57680, SPIRAM 0/0</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">--Task-- Total DRAM D/IRAM IRAM SPIRAM +/- DRAM D/IRAM IRAM SPIRAM</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">no task 5312 0 0 0 +5312 +0 +0 +0</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">esp_timer 52328 0 644 0 +52328 +0 +644 +0</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">main 16448 0 0 0 +16448 +0 +0 +0</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">ipc0 11096 0 0 0 +11096 +0 +0 +0</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">Housekeeping 40576 5120 0 0 +40576 +5120 +0 +0</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">tiT 128 0 0 0 +128 +0 +0 +0</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">Tmr Svc 884 6444 0 0 +884 +6444 +0 +0</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">ipc1 12 0 0 0 +12 +0 +0 +0</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">AsyncConsole 20 0 26404 0 +20 +0 +26404 +0</span></font></div></blockquote></blockquote><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class=""><br class=""></span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">Without deriving OvmsCommand from ExternalRamAllocated:</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class=""><br class=""></span></font></div></blockquote><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">Free 8-bit 119240/282436, 32-bit 424/27596, SPIRAM 4193924/4194252</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">--Task-- Total DRAM D/IRAM IRAM SPIRAM +/- DRAM D/IRAM IRAM SPIRAM</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">tiT 0 0 0 128 +0 +0 +0 +128</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">Housekeeping 40564 5120 0 12 +40564 +5120 +0 +12</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">no task 5348 0 0 0 +5348 +0 +0 +0</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">esp_timer 52328 0 644 0 +52328 +0 +644 +0</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">main 16448 0 0 0 +16448 +0 +0 +0</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">ipc0 11096 0 0 0 +11096 +0 +0 +0</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">ipc1 12 0 0 0 +12 +0 +0 +0</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">Tmr Svc 884 6444 0 0 +884 +6444 +0 +0</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">AsyncConsole 20 0 26404 0 +20 +0 +26404 +0</span></font></div></div></blockquote></blockquote><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class=""><br class=""></span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">After deriving OvmsCommand from ExternalRamAllocated:</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class=""><br class=""></span></font></div></blockquote><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">OVMS > module memory</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">Free 8-bit 152308/282432, 32-bit 424/27596, SPIRAM 4160852/4194252</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">--Task-- Total DRAM D/IRAM IRAM SPIRAM +/- DRAM D/IRAM IRAM SPIRAM</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">esp_timer 31664 0 644 20664 +31664 +0 +644 +20664</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">tiT 0 0 0 128 +0 +0 +0 +128</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">Housekeeping 39636 0 0 6060 +39636 +0 +0 +6060</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">no task 5348 0 0 0 +5348 +0 +0 +0</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">main 16448 0 0 0 +16448 +0 +0 +0</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">ipc0 11096 0 0 0 +11096 +0 +0 +0</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">ipc1 12 0 0 0 +12 +0 +0 +0</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">Tmr Svc 7328 0 0 0 +7328 +0 +0 +0</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">AsyncConsole 20 0 26404 0 +20 +0 +26404 +0</span></font></div></div></blockquote></blockquote><div class=""><br class=""></div><div class="">The advantage of SPI RAM is obvious. 30KB of internal RAM saved with just one line changed in a header file. Most of our other objects like that (metrics, configs, etc) could be equally easily moved to SPI RAM. We can make the decision on a class-by-class basis.</div><div class=""><br class=""></div><div class="">I think this is a pretty good solution. It puts the onus of the decision of whether to put into SPI RAM into the object itself (as presumably the object knows best whether it can actually be put in SPI RAM). It is also extremely simple to define that.</div><div class=""><br class=""></div><div class="">But, it is an experiment. Please let me know what you think.</div><div class=""><br class=""></div><div class="">Regards, Mark.</div><div class=""><br class=""></div></body></html>