'Storing' variables in RAM
6 views (last 30 days)
Is there a way to store data without writing it to the drive?
Result should be that 'clear all' does not affect the variable/handle, but EEPROM doesn't constantly have to be written to. Similar to the Instrument Toolbox, where instruments are kept regardless of what happens in the workspace and are only removed with the 'delete'-command.
And yes, i know, 'Don't use clear all, it's resource intensive and almost never necessary'. Not an option.
Jan on 7 May 2021
Edited: Jan on 7 May 2021
Store the wanted data persistently:
function Out = DataVault(Cmd, Name, Data)
Stored.(Name) = Data;
Out = Stored.(Name);
Stored = ;
error('Jan:DataValut:BadCmd', 'Unknown command: [%s]', Cmd);
Now call it:
ValuableData = 4711;
DataVault('store', 'Box1', ValuableData);
ValuableData = DataValut('get', 'Box1')
Of course, clean code would simply omit all clear all calls, because they remove all (unlocked) functions from the memory. You say, that this is not an option. I resist on preferring trustworthy code, which does not contain junk.
If the clear all comes from evil subfunctions, you can either shadow the clear command by defining your own clear function, or if they are scripts, define a variable "all", such that "clear all" clears this variable only. Brrr.