Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to delete the temporary files? #5

Open
GoogleCodeExporter opened this issue Mar 14, 2015 · 6 comments
Open

How to delete the temporary files? #5

GoogleCodeExporter opened this issue Mar 14, 2015 · 6 comments

Comments

@GoogleCodeExporter
Copy link

I have a loop in my program and at each iteration I'm creating a plot that
is displayed. But since there are more than GP_MAX_TMP_FILES iterations I
get an exception. How do I properly clean up the temporary files in each
iteration?

What steps will reproduce the problem?
1. Create more than GP_MAX_TMP_FILES plots.

What version of the product are you using? On what operating system?
I'm using the latest version running on linux.

Original issue reported on code.google.com by [email protected] on 23 Oct 2009 at 8:20

@GoogleCodeExporter
Copy link
Author

I found out that Gnuplot::remove_tmpfiles() isn't thread safe. I'm using 
threads.
So why do we have a limit on the total number of temporary files? Can't we just
delete all temporary files when destructing?

Original comment by [email protected] on 23 Oct 2009 at 8:43

@GoogleCodeExporter
Copy link
Author

I'm also wondering the proper way to do this.  If I delete the tmp files 
immediately
after calling plot_x(), they're gone by the time gnuplot tries to read them.

Original comment by [email protected] on 25 Mar 2010 at 5:49

@GoogleCodeExporter
Copy link
Author

[deleted comment]

@GoogleCodeExporter
Copy link
Author

I was using this library to graphically the differences between several sorting 
algorithms. I made this method:

void Gnuplot::remove_oldest_tmpfile(){
    if ((tmpfile_list).size() > 0)
    {
        remove (Gnuplot::tmpfile_list[0].c_str() );
        Gnuplot::tmpfile_list.erase(Gnuplot::tmpfile_list.begin());
        Gnuplot::tmpfile_num=tmpfile_list.size();
    }
}

You call it when you're at the maximum number of temp files, and it will remove 
the oldest. This generally allows gnuplot to plot the graph in time, so you 
don't get the race condition that Kyle mentioned above. It allowed me to 
rapidly-plot about 50% faster.

Original comment by [email protected] on 14 Apr 2014 at 8:15

@Iampizzaprincess
Copy link

The void Gnuplot::remove_oldest_tmpfile() is very helpful! I made one addition, though, to check if the file exists before attempting to delete it (otherwise I kept getting segmentation faults and kept crashing my program). I altered the function so it looks something like this:

void Gnuplot::remove_oldest_tmpfile(){
if ((tmpfile_list).size() > 0)
{
struct stat buffer;
if (stat (tmpfile_list[0].c_str(), &buffer) == 0) { // check if file exists
remove (Gnuplot::tmpfile_list[0].c_str() );
}
else {
std::cout << "oldest tmp file DNE \n\n";
}
Gnuplot::tmpfile_list.erase(Gnuplot::tmpfile_list.begin());
Gnuplot::tmpfile_num=tmpfile_list.size();
}
}

Thanks for the help!

@orbitcowboy
Copy link
Owner

Thanks! Could you provide a pull request?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants