大型2D阵列时出现段故障 [英] Seg fault in case of large 2D array

查看:169
本文介绍了大型2D阵列时出现段故障的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个程序来对DNA序列进行一些分析.除了这件事,一切都正常.我想声明一个大小为m * n的2D数组,其中m和n是从输入文件中读取的.现在的问题是,如果m和n太大.例如,如果m = 200且n = 50000然后在声明数组的那一行出现段错误.

I am writing a program to do some analysis on DNA sequences. Everything works fine except for this thing. I want to declare a 2D array of size m*n where m and n are read from an input file. Now the issue is that if m and n goes too large. As an example if m = 200 and n = 50000 then I get a seg fault at the line where I declare my array.

array[m][n];

任何想法如何克服这一点.我确实需要这样一个数组,因为我的整个逻辑取决于如何处理该数组.

Any ideas how to overcome this. I do need such an array as my entire logic depends on how to process this array.

推荐答案

可能您的堆栈空间不足.
您不能使用 malloc 在堆上动态分配数组吗?

Probably you are running out of stack space.
Can you not allocate the array dynamically on heap using malloc?

您可能想看看

You may want to have a look at this answer if you do not know how to do that.

这篇关于大型2D阵列时出现段故障的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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