在C中保留RAM
发布时间:2020-12-16 07:52:43 所属栏目:百科 来源:网络整理
导读:我需要关于如何编写一个保留指定数量的MB RAM的C程序的想法,直到一个键[例如任何键]在 Linux 2.6 32位系统上按下. */.eat_ram.out 200# If free -m is execute at this time,it should report 200 MB more in the used section,than before running the prog
我需要关于如何编写一个保留指定数量的MB RAM的C程序的想法,直到一个键[例如任何键]在
Linux 2.6 32位系统上按下.
* /.eat_ram.out 200 # If free -m is execute at this time,it should report 200 MB more in the used section,than before running the program. [Any key is pressed] # Now all the reserved RAM should be released and the program exits. * 它是程序的核心功能[保留RAM]我不知道如何做,从命令行获取参数,打印[任何键被按下]等等是不是我的问题. 有什么想法如何做到这一点? 解决方法
你想使用malloc()这样做.根据您的需要,您还需要:
>将数据写入内存,使内核实际上保证它.你可以使用memset()这个. 在大多数现实中,malloc()和memset()(或者,有效地执行相同的calloc())将适合您的需要. 最后,当然,当你不再需要时,你想释放()内存. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |