2

In the c++ program that I am trying to write I would need to update a 2D array and then plot it (for plotting I have been using gnuplot) for a pretty big number of times. I would like, if possible, to avoid having a huge file in which I would write the matrix for every step of the evolution to plot everything afterwards.

My intention was to do a gnuplot script able to run the program to evolve the matrix once and then print it and then iterate. But to do so I would need to give to the program access to the matrix calculated in the prior step and I cannot figure out an efficient way to do it. Being able to keep the matrix in memory between runs and passing only a pointer from one step to the other seems fast but I do not know if it is possible.

Do you know if it is possible to keep a variable in memory between runs or do you have alternative suggestions?

Thanks.

Tom Solid
  • 2,226
  • 1
  • 13
  • 32

2 Answers2

2

You should open Gnuplot inside your c++ program, and communicate with it using a FIFO as in this answer.

After that, you can polt your array for example:

std::stringstream ss;
ss << "plot '-' nonuniform matrix with image\n";
/*... filling ss with your array*/
ss << "e\ne\n\n";
fprintf(gp, ss.str().c_str());
fflush(gp);
Ted Lyngmo
  • 93,841
  • 5
  • 60
  • 108
Tom Solid
  • 2,226
  • 1
  • 13
  • 32
0

You can use a memory-mapped file.

Boost provides for a cross-platform shared-memory file.

Check out the documentation.

YScharf
  • 1,638
  • 15
  • 20