在程序之间保持内存中的变量

发布于 2025-01-26 05:38:58 字数 349 浏览 2 评论 0原文

在我要编写的c ++程序中,我需要更新2D数组,然后绘制它(为了绘制我一直在使用gnuplot)时间。 如果可能的话,我想避免有一个巨大的文件,在该文件中,我会为演变的每个步骤编写矩阵,以绘制所有内容。

我的目的是进行gnuplot脚本能够运行程序以进化矩阵一次,然后打印然后迭代。但是要这样做,我需要将程序访问到上一步中计算的矩阵访问权限,我无法找到一种有效的方法来执行此操作。能够将矩阵保持在运行之间的内存中,并且仅将指针从一个步骤传递到另一个步骤似乎很快,但我不知道是否可能。

您知道是否有可能在运行之间的内存中保留变量,还是有其他建议?

谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不即不离 2025-02-02 05:38:58

您应该在c ++程序内打开gnuplot,并使用fifo与此答案

之后,例如,您可以polt阵列:

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);

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);
¢蛋碎的人ぎ生 2025-02-02 05:38:58

您可以使用内存映射文件。

boost提供了跨平台 共享模式文件。

请查看

You can use a memory-mapped file.

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

Check out the documentation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文