I am trying to write a program which will generate a list of objects and then exports it in a separate file and clears its memory. As an example I tried the following
Do[{Subscript[l, p] = Table[Subscript[l, p, i], {i, 10}];
Export["\!\(\*SubscriptBox[\"l\", \"p\"]\).mnaz",
Compress[Subscript[l, p]], "String"]; Clear[Subscript[l, p]]}, {p,
1, 3}]
Of course, the above is just a sample (and my actual list(s) are more bulky (actually they are list of matrices)), but I hope it explains the spirit. I wanted to export each list separately so that I can get separate files like l_1.mnaz
, l_2.mnaz
etc., which I can import again by using the same type of code.
Motivation: I need to actually generate a huge list of data. However whatever I do, my system goes out of memory after 5000 loops, which itself takes a lot of time. One reason is that, I need to modify the list at each loop. It seems 1000 loops takes a reasonable time. Hence I am trying to break the loop into smaller chunks, export the data, and clear the memory for the next loop. Clear[Subscript[l, p]]
is used for that purpose.
"\!\(\*SubscriptBox[\"l\", \"p\"]\).mnaz"
would not work. One could instead use:ToString[Subscript[l, p], TeXForm] <> ".mnaz"
or if the file system supports it something besidesTeXForm
. $\endgroup$