在程序之间保持内存中的变量
在我要编写的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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该在
c ++
程序内打开gnuplot
,并使用fifo与此答案。之后,例如,您可以polt阵列:
You should open
Gnuplot
inside yourc++
program, and communicate with it using a FIFO as in this answer.After that, you can polt your array for example:
您可以使用
内存映射
文件。boost
提供了跨平台
共享模式
文件。请查看。
You can use a
memory-mapped
file.Boost
provides for across-platform
shared-memory
file.Check out the documentation.