使变量即使在程序终止后仍然存在 [英] Making variables persist even after program termination

查看:61
本文介绍了使变量即使在程序终止后仍然存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让一个变量即使在程序终止后也可以保留.换句话说,我希望即使在应用程序从主函数退出后,变量仍保留在内存中.因此,如果我的应用程序再次启动,它可以直接从内存访问该变量.这有可能吗?将动态分配,例如 array = new int [size] ,这有技巧吗?

I would like to have a variable to persist even after program termination. In other words, I'd like for a variable to remain in the memory even after an application exits from the main function. So, if my application is launched again, it could access that variable directly from the memory. Is this even possible? Would dynamic allocation, e.g. array=new int[size], do the trick?

推荐答案

否,进程终止时os会回收所有内存.您必须将所需的内容保存到文件中.

No, all memory is reclaimed by the os on process termination. You have to save stuff you want to a file.

这篇关于使变量即使在程序终止后仍然存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆