[英]So much memory being malloc'd that I get “Killed” when running my program deep enough
I have a program that goes n^2 layers deep of recursion and mallocs a bunch of memory to concatenate char*s together. 我有一个程序,可以进行n ^ 2层递归深度处理,并分配一堆内存以将char * s连接在一起。 With a large enough n, the process just gets killed by the server (since it is consuming too much memory).
如果n足够大,则进程只会被服务器杀死(因为它消耗了太多的内存)。 How can I release this memory and still have my data?
如何释放此内存并仍然有我的数据?
It's mallocs look like 它的malloc看起来像
test = (char *)malloc(sizeof(char) * 256);
I need this data straight until the end of the program. 我需要这些数据,直到程序结束。 How can I deal with this?
我该如何处理?
You can't. 你不能 Once you release the memory the data is gone.
释放内存后,数据就消失了。
What you may be able to do is to make better use of the memory you have available. 您可能能够做的是更好地利用可用的内存。 With the code you posted, I can't think of a way to help you manage the memory any better though
使用您发布的代码,我想不出一种方法来帮助您更好地管理内存
Without thinking about it deeper, why do you need all of the data in memory? 不用更深入地思考,为什么需要内存中的所有数据? Several things you need to do:
您需要做的几件事:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.