String[] array;
int value;
Thread thread;
void setup() {
// Initialize the array and value
array = new String[10];
value = 42;
// Start a new thread to save the file
thread = new Thread(new Runnable() {
public void run() {
saveFile(array, value); }});
thread.start();
}
void draw() {
// Do something else while the file is saving
}
void saveFile(String[] array, int value) {
saveStrings("Generic file"+str(value)+".txt",array);println("Done");
}
This seems to work…I needed to write files but I didnt want the code to stop every time I needed to write a file…My question is can this be improved…or am I doing anything naughty https://chat.openai.com/chat
Edit Thanks to GoToLoop the saveFile thread should be:
void saveFile(String[] loc_array, int loc_value) {
saveStrings("Generic file"+str(loc_value)+".txt",loc_array);println("Done");}
Yeah but the normal way shown in the reference does not allow for passing variables or arrays…already trried that. If you have a better solution then I would like to see it…of course I am not calling this thing in set up…just showing as an example and want verification that this is the correct way of doing it.
its just the most basic example to show it working. In my program I am playing around with a quadratic sieve…so I need to save a bunch of variables or else the computer will run into memory problems. Also the state of those variables is important…if I use global variables then the array could change before I write the file.
I stumbled across a bug in my code…it turns out that when you pass the array and the size of the array…it takes time to spin up the thread and in the mean time those values can change…so you need to pass a copy of those instead of the original…